由于#被认为是/ etc / ansible / hosts中的注释,我无法使用包含尖锐的密码。
[hosts] host1 ansible_ssh_user=user ansible_ssh_pass=userpass ansible_su_pass=My#Password
然后用一个原始命令:
$ ansible host1 -m raw -a "whoami" --su host1 | FAILED | rc=1 >> su: Authentication failure
如果我使用密码没有#它工作正常。 有没有解决这个问题的方法?
在清单文件中,下面的例子给出了所需的结果。
[hosts:vars] ansible_su_pass=My#Password
但是这个variables与主机组中的所有主机相关,所以更好的办法是创build一个文件“/ etc / ansible / host_vars / host1”,并在里面放置:
ansible_su_pass: My#Password
您可以使用#内联,通过\转义它,即ansible_su_pass=My\#Password 。 确保您使用最新的Ansible,因为iniparsing器随着时间的推移而发展。