Thanks for your earlier reply Adam.

So how can I combine variables for a list of "users" defined like so:

*group_vars/all*

users:
  - name: alice
    comment: Alice

*group_vars/group1*

users:
  - name: bob
    comment: Bob

*host_vars/host1*

users:
  - name: charlie
    comment: Charlie

How can all these variables be combined using "loop" or "with_items"?
What if there are duplicates?
Can the "host_vars/host1" variables override and take precedence over the 
"group_vars/all" variables?

Regards,
Suhail.

On Sunday, 3 March 2019 00:25:46 UTC, Adam E wrote:
>
> I have a similar issue and solved it by this PR 
> https://github.com/ansible/ansible/pull/51466 . if you want to use it, 
> just grab the source code and add it to your local library directory until 
> it's merged.  Also see this thread 
> https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/ansible-project/Ssnk6exNjNs/sCKlrOp_FQAJ
>
> With the approach above, the code would merge together all lists that 
> match a pattern, this way you can defined as many "users" variables as you 
> want as long as they are unique and start with say "users_"
>
> If you don't want to copy the library or wait for the PR, then you could 
> also just merge a set of predefined lists.
>
> ie..  
> with_items: "{{ users_host|default([]) + users_group_l1|default([]) + 
> users_group_l2|default([[) }}"
>
>

-- 
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/6e8b7c8b-2c76-4104-8fa9-9297b2109db6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to