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?
 

-- 
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/cf7f8b7e-72e4-4988-b362-57bde4101a76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to