I have a list that I would like to use to see if any of the members of the list are in a second list, and use that in an Ansible when clause. Can this be done in a one-liner?
- name: task include moar ansible
  include: more_tasks.yaml
  when: any_member_of_this_list in some_other_list
This is quite easy. Ansible introduced some extra Jinja filters, and one of them is intersect, which returns unique elements which are contained in two lists. Since an empty list is falsy and a non-empty list is truthy, there is not more to be done than this:
when: any_member_of_this_list | intersect(some_other_list)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With