I have a very complex Ansible setup with thousands of servers and hundreds of groups various servers are member of (dynamic inventory file).
Is there any way to easily display all groups that a specific host is member of?
I know how to list all groups and their members:
ansible localhost -m debug -a 'var=groups'
But I want to do this not for ALL hosts, but only for a single one.
There is
group_names
magic variable:cat /etc/ansible/hosts | grep -e [[] && ansible all --list-hosts
Create a playbook called 'showgroups' (executable file) containing:
You can run it like this to show the groups of one particular host (-l) in your inventory (-i):