Ansible - How to read group names in the host inventory file?

Viewed 5152
[dev]
fitness.dev

[nginx]
fitness.dev
fitness.staging
www1.fitness.tld
www2.fitness.tld

[webserver]
nginx

for example result of some step in a playbook.

tasks:
- name: Print out the group_names
  debug: msg="{{ hostvars.group_names[] }}"

I'm specfic about only group_names in the host inventory file.

like:

hostvars.groups_names[0]  is dev  
hostvars.groups_names[1]  is nginx 
hostvars.groups_names[2]  is webservers 
0 Answers
Related