Need guidance with multi-level role variables

49 views
Skip to first unread message

Willard Dennis

unread,
Nov 14, 2014, 12:09:48 PM11/14/14
to ansible...@googlegroups.com
Hi all,

I have some role variables currently that are single-level, for example a list of IT users:

# Members of the IT Dept.
it_users:
  - bill
  - fred
  - sam

Now, for another role I'm defining, I'll need to include some data for each user, such as UID, password hash, homedir path, so I can properly set up local accts via the user module. How do I properly define attributes for each user, and then pull them in to the arguments of the user module?

Thanks,
Will

Tore Olsen

unread,
Nov 17, 2014, 5:31:22 AM11/17/14
to ansible...@googlegroups.com
Hi Willard,

Keeping information in one place, is there a reason why you cannot change it_users to be dictionaries?

it_users:
  - { name: bill, uid: 501, passwd: hash, home: /home/bill }
  - { name: fred, uid: 501, ... }
  - { name: sam, ... }

Now you can access these items in the user module or elsewhere like this:

- user: name={{ item.name }} home={{ item.home }} password={{ item.passwd }}
  with_items: it_staff

Regards,
-Tore

Willard Dennis

unread,
Nov 17, 2014, 1:56:56 PM11/17/14
to ansible...@googlegroups.com
This is what I was looking for! Thanks!

- Will
Reply all
Reply to author
Forward
0 new messages