Var substitution help

16 views
Skip to first unread message

Dimitri Yioulos

unread,
Jan 18, 2017, 9:12:27 AM1/18/17
to Ansible Project
Hello, all.

A while ago, I created a quck-'n-dirty user creation playbook.  With the following line, I was able to both create the user, and his/her encrypted password (for CentOS 6/7):

user: name="someuser" password={{ 'somepassword'|password_hash('sha512', 'mSFRM"N4') }} state=present

Now, I want to user "user" and password" vars in the play, rather than have to add them in the line above.  Here's what I've come up with:

vars:
   user: someuser
   password: somepassword

tasks:
   - name: create user in Centos 6
     user: name={{ user }} password={{ '{{ password }}'|password_hash('sha512', 'ies8Aech') }} state=present

With the above, while the user is created, the password doesn't work.  Help would be appreciated.

Dimitri

Kai Stian Olstad

unread,
Jan 18, 2017, 9:43:47 AM1/18/17
to ansible...@googlegroups.com
On 18. jan. 2017 15:12, Dimitri Yioulos wrote:
> tasks:
> - name: create user in Centos 6
> user: name={{ user }} password={{ '{{ password
> }}'|password_hash('sha512', 'ies8Aech') }} state=present
>
> With the above, while the user is created, the password doesn't work. Help
> would be appreciated.

You can't use template in a template, loose the inner {{ }} lik so.
user: name={{ user }} password={{ password | password_hash('sha512',
'ies8Aech') }} state=present

--
Kai Stian Olstad

Dimitri Yioulos

unread,
Jan 18, 2017, 10:35:17 AM1/18/17
to Ansible Project
Thank you, Kai!  Works fine now.
Reply all
Reply to author
Forward
0 new messages