The real goal here is to perform an action only when at least one of
inventory_hostname groups from
group_names matches one group from another list of groups (in this example: ```
git|local|ntopng```) .
This is defined within a role, so I cannot use the list ``` - hosts:```.
For instance, to print all hostname variables only when inventory_hostname belong to at least one of git,local or ntopng groups,I tried this:
- name: Print all variables for "{{ inventory_hostname }}" system device (except any role parameters)
debug:
var: hostvars[inventory_hostname]
when: group_names | map('regex_search', "^(git|local|ntopng)$") | list | length > 0
It does not work as expected, because the length always returns the number of groups within group_names. It seems that length considers a null element as defined and counts it."is defined" does not work either for the same reason.
I cannot find a way to test if at least one element of the search is not null.
Any suggestion?