问题
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