This does seem to do the trick. Now I just need to experiment with it a bit 
to see how it works with "with_subelements" type iterators.


On Friday, August 4, 2017 at 10:27:00 PM UTC-7, Toshio Kuratomi wrote:
>
> I think the intersect() filter is what you are looking for:
>
> http://docs.ansible.com/ansible/latest/playbooks_filters.html#set-theory-filters
>
> Here's what  I think (untested) your task would look like:
>
> tasks:
>   - name: Test
>   debug:
>     msg: "Do a thing to {{ item }} on {{ inventory_hostname }}"
>   with_items: "{{ users }}"
>   when: item.employee_roles | 
> intersect(hostvars[inventory_hostname].active_system_roles)
>
>
> -Toshio
>
> On Fri, Aug 4, 2017 at 1:55 PM, Tim Gaastra <[email protected] 
> <javascript:>> wrote:
>
>> Is there any way in Ansible to succinctly test for set membership in a 
>> list, from a list?
>>
>> An example in psuedo-Ansible code:
>>
>> users:
>>    - name: Jim
>>      employee_roles:
>>         - Admin
>>    - name: Bob
>>      employee_roles:
>>         - DBA
>>    - name: Suz
>>      employee_roles:
>>         - Developer
>>    - name: Kev
>>      employee_roles:
>>         - DBA
>>         - Developer
>>
>> Then, in group vars for a set of hosts:
>>
>> group-a 
>> ----------
>> active_system_roles:
>>    - Admin
>>    - DBA
>>
>> group-b
>> ----------
>> active_system_roles:
>>    - Admin
>>    - Developer
>>
>> I'd like a task that could do something like (aware this isn't real code):
>>
>> tasks:
>>    - name: Test
>>      debug:
>>          msg: "Do a thing to that user on this host"
>>      with_items: "{{ users }}"
>>      when: item.employee_roles in 
>> hostvars[inventory_hostname].active_system_roles
>>
>> I.E. if any of the employee's roles are in the list of 
>> active_system_roles, do a thing to that user on that host.
>>
>>
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/95025760-a26b-4a13-bdf4-60294f84d325%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/95025760-a26b-4a13-bdf4-60294f84d325%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/2dd88c19-02ae-4b28-a2d2-2691e8742e69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to