Awesome! Thank you so much for your responses Michael, Brian, and
Adam. Both solutions from Brian and Adam work, thank you! If any of
you get to Los Angeles I owe you a drink!

This is working great:

  - name: Users | create .gitconfig
    shell: git config --global user.name '{{ item.value.name }}'; git
config --global user.email '{{ item.value.mail }}'
    args:
      creates: /home/{{ item.key }}/.gitconfig
    sudo: yes
    sudo_user: "{{ item.key }}"
    with_dict: users
    when: item.key in allowed_users_dev
    tags: git

What I like about the with_dict approach is I can do "when: item.key
not in allowed_users_dev" with "user: name={{ item.key }}
state=absent".



On Fri, Oct 10, 2014 at 9:35 AM, Adam Heath <a...@brainfood.com> wrote:
> - name: foo
>   shell: echo "{{ users[item].name }}"
>   with_items:
>    - alice
>    - bob
>
>
> On 10/10/2014 01:59 AM, Michael Bushey wrote:
>>
>> Thanks for your response Michael. I've already read through that page
>> a few times. It does not work for me because I need an array of users,
>> and  then I need to be able to select which user have access to each
>> class of server. This method would give every user access to every
>> machine. I need to be able to specify something like with items -
>> users.alice - users.bob and not have carol included.
>>
>>
>>
>>
>>
>> On Thu, Oct 9, 2014 at 11:20 PM, mvermaes <mverm...@gmail.com> wrote:
>>>
>>> Hi Michael, I think you want something like:
>>>
>>> ---
>>> - name: Set up users
>>>    hosts: localhost
>>>    gather_facts: no
>>>
>>>    vars:
>>>      users:
>>>        alice:
>>>          name: Alice Appleworth
>>>          mail: al...@appleworth.com
>>>          pass: ..hash...
>>>        bob:
>>>          name: Bob Bananarama
>>>          mail: b...@bananarama.com
>>>          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: al...@appleworth.com
>>>>          pass: ..hash...
>>>>      - bob:
>>>>          name: Bob Bananarama
>>>>          mail: b...@bananarama.com
>>>>          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 a topic in the
>>> Google Groups "Ansible Project" group.
>>> To unsubscribe from this topic, visit
>>>
>>> https://groups.google.com/d/topic/ansible-project/-TzTFS57j7A/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> ansible-project+unsubscr...@googlegroups.com.
>>> To post to this group, send email to ansible-project@googlegroups.com.
>>> 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.
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/-TzTFS57j7A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/54380AE6.3070902%40brainfood.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPJTyAUM4oS-oAnmgKTtgzoVXMy5xEtZjjo265B%3DQD5HYvqp_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to