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 ?

Arka
  • 173
  • 1
  • 2
  • 8

2 Answers2

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
Arka
  • 173
  • 1
  • 2
  • 8
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.