On 01. nov. 2017 12:44, Dick Visser wrote:
> I have a few use cases where I define a list in group_vars/all.yml,
> for instance a list of users:
> 
> users:
>    - allen
>    - bob
>    - chris
>    - dick
> 
> 
> So this list applies to all hosts in my case.
> 
> But for a specific host, I want to add one entry to the list.
> The only way I can get that to work is by copying the list in
> host_vars/somehost/main.yml and just manually add it:
> 
> users:
>    - allen
>    - bob
>    - chris
>    - dick
>    - extrauser
> 
> Obviously this is not ideal as any changes made to the first var will
> have to be manually carried over to the specific instances.
> 
> Is there some way to append items to list vars (or subtract, for that matter)?
> 
> I was hoping to be able to use something like:
> 
> users: "{{ users }} + ['extrauser']"
> 
> But that gives me "recursive loop detected in template string".
> 
> Any other/clean ways to solve this?
Use two variable users and extra_users on host that need to have some extra 
users.

Then you can use this, because of default this will not fail on host that do 
not have extra_users varaible set.

{{ users | union(extra_users | default([])) }}


-- 
Kai Stian Olstad

-- 
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/641daef5-f08b-274b-06ad-88770b53619f%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to