Ansible Special Characters in passwords

谁说胖子不能爱 提交于 2021-02-10 12:00:57

问题


I read my root passwords from an encrypted ansible-vault file. But when I use it on ansible_become_pass the operation fails because the password contains a special character. In my example "#"

This is my yml:

- hosts: sirius
  remote_user: ansusr
  become: yes
  vars_files:
     - vault_vars.yml
  become_pass: "{{ root_pass_sirius }}" 

ansible-playbook check.yml --ask-vault-pass

fatal: FAILED! => {"msg": "{{ TesT#1234 }}: template error while templating string: unexpected char '#' at 6. String: {{ TesT#1234 }}"}

How to mask the # Char?


回答1:


Use set +H before actually running that encryption command.




回答2:


This might work.

become_pass: "{{ root_pass_sirius | regex_escape() }}" 



回答3:


Try single quotes instead of double:

become_pass: '{{ root_pass_sirius }}'



回答4:


Another thing that you can try is the quote filter:

become_pass: "{{ root_pass_sirius | quote }}" 



回答5:


Try this "'"{{ }}"'"

or this $'{{ }}'

Its Jinja templates



来源:https://stackoverflow.com/questions/49153403/ansible-special-characters-in-passwords

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!