Hi Michael, I think you want something like:
---
- name: Set up users
hosts: localhost
gather_facts: no
vars:
users:
alice:
name: Alice Appleworth
mail: [email protected]
pass: ..hash...
bob:
name: Bob Bananarama
mail: [email protected]
pass: ..hash..
tasks:
- name: Add user
debug: msg="Add user {{ item.key }} password {{ item.value.pass }}"
with_dict: users
Here's the section of the docs you want -
http://docs.ansible.com/playbooks_loops.html#looping-over-hashes
On Friday, October 10, 2014 7:36:25 AM UTC+8, Michael Bushey wrote:
>
> I would like to be able to put my users into a list and be able to select
> what user has access to each machine.
>
> ---
> - name: Set up users
> hosts: localhost
> gather_facts: no
>
>
> vars:
> - alice:
> name: Alice Appleworth
> mail: [email protected] <javascript:>
> pass: ..hash...
> - bob:
> name: Bob Bananarama
> mail: [email protected] <javascript:>
> pass: ..hash..
> mail:
>
> tasks:
> - name: Add user
> debug: msg="Add user {{ item.key }} password {{ item.pass }}"
> with_items:
> - "{{ alice }}"
>
>
> I am not able to figure out how to get the user name, ie "alice" as
> item.key is not valid. I think this is because using "{{ alice }}" does not
> preserve the name. Does anyone know how I can structure this? I've tried
> putting them all under users, but with_items: users.alice does not work.
>
> Thanks in advance for any help. The docs do not seem to cover this and
> I've Googled Ansible arrays and dicts to the point where I'm not finding
> any new pages.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/90226003-8d97-4e92-8bb5-c8ec56b3717c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.