Oneliner to assert all elements of a list

Viewed 71

In Ansible, I'm trying to find a oneliner to assert that all elements of a list match a regex using a python generator.

Something like:

- assert:
    that:
      - (item is match('{{ regex }}') for item in list)

But I can't figure out the right syntax.

Is it possible ? How ?

1 Answers

One possible solution: use the select filter to reduce the list to elements matching your regex and compare the size of resulting list with orignal:

- assert:
    that:
      - (my_list | select('match', my_regex) | list | length) == (my_list | length)
Related