- 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 <[email protected]> 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: [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]
pass: ..hash...
- bob:
name: Bob Bananarama
mail: [email protected]
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
[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.
--
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/54380AE6.3070902%40brainfood.com.
For more options, visit https://groups.google.com/d/optout.