following is the content of my "hosts" file. how to print which groups "web_svr1" is part of? it should print all_servers and web_servers.
[web_servers]
web_svr1
web_svr2
[app_servers]
app_svr1
[all_servers:children]
web_servers
app_servers
I tried below code to print group names but it doesn't work.
- name: Debug task to print group names
ansible.builtin.debug:
msg: "Host belongs to group:"
loop: "{{ group_names }}"
i figured it out, {{ item }} will iterate through group_names
group_names[0] will be all_servers group_names[1] will be web_servers