How do you search for substring in ansible group_names?

Solution 1:

You can select and count items with filters:

when: group_names | select('search','hello') | list | count > 0

Solution 2:

You can also use join and search:

when: group_names|join(" ")|search("hello")