Hello Adam E,
You have got the implementation correct. Intersect is the correct method to
be used.
You may refer the playbook mentioned below:
- hosts: localhost
vars:
list1: ['value1', 'value2']
list2: ['value3', 'value4']
tasks:
- name: Find intersection
debug:
msg: "{{ list1 | intersect(list2) | length }}"
register: List.Length
- name: Returns True/False
debug:
msg: "{% if List.Length > '0' %} returns True{% else %} returns
False{% endif %}"
Thanks
Soniya
On Thursday, April 4, 2019 at 4:19:50 AM UTC+5:30, Adam E wrote:
>
> Hi, wondering if there is any cleaner way to see if two lists have 1 or
> more intersecting values?
>
> the following works for me
>
> # returns true
>> {{ ['value1', 'value2'] | intersect(['value1', 'value2']) | length > 0 }}
>> # returns false
>> {{ ['value3', 'value4'] | intersect(['value1', 'value2']) | length > 0 }}
>
>
> just wondering if there is a cleaner looking solution that I am not aware
> of as I am using it frequently.
> something like would be handy.
>
>> {{ ['value1', 'value2].any(['value1', 'value2']) }}
>
>
--
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/f6e53363-7707-46c6-aa5c-99679152c272%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.