1

Since # is considered as a comment in /etc/ansible/hosts I'm unable to use a password containing a sharp.

[hosts]
host1 ansible_ssh_user=user ansible_ssh_pass=userpass ansible_su_pass=My#Password

Then with a raw command:

$ ansible host1 -m raw -a "whoami" --su
host1 | FAILED | rc=1 >>

su: Authentication failure

If I use a password without a # it works fine. Is there a workaround to this ?

2 Answers 2

1

In the inventory file the example below give the desired result.

[hosts:vars]
ansible_su_pass=My#Password

But the variable is then related to all hosts in the hosts group so a better way is to create a file "/etc/ansible/host_vars/host1" and put the following inside :

ansible_su_pass: My#Password
1

You can use # inline, by escaping it with \, i.e ansible_su_pass=My\#Password. Make sure you're using the latest Ansible as ini parser has evolved over time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .