Ansible Playbook and syntax issue with variables
7,576
Yes, it's a simple typo.
salt: "{{ lookup('password', '/dev/null length=10' chars=ascii_letters) }}"
You can see that the error complained about the literal text chars
appearing unexpectedly. That's because you closed the quote early, where it was supposed to contain all of the options, i.e.:
salt: "{{ lookup('password', '/dev/null length=10 chars=ascii_letters') }}"
Related videos on Youtube
Author by
Nicolas
Updated on September 18, 2022Comments
-
Nicolas over 1 year
I'm trying to execute the below playbook I wrote but it fails on some syntax errors.
I tried few things from the online doc but without sucess so far. The aim of these variable is to generate a random password to be used by the user module in a role.
- hosts: all remote_user: root become : no vars: salt: "{{ lookup('password', '/dev/null length=10' chars=ascii_letters) }}" pasw: "{{ lookup('password', '/dev/null length=15') }}" hash: "{{ pasw }} | password_hash('sha512', {{ salt }}) " roles: - ansiuser
the error from ansible-playbook execution (it fails at role execution so I guess my variables aren't doing what I'm looking for: generating strings)
TASK [ansiuser : Set the password fact for this host] ****************************************************************************************************************** fatal: [192.168.11.100]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ pasw }} | password_hash('sha512', {{ salt }}) '. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ lookup('password', '/dev/null length=10' chars=ascii_letters) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: template error while templating string: expected token ',', got 'chars'. String: {{ lookup('password', '/dev/null length=10' chars=ascii_letters) }}"}
-
Nicolas over 5 yearsoh … you'r perfectly right, that's so stupid of me … thanks a lot for your assistance there