Is there any option to list groups in Ansible?

Question:

As far as i know, ansible has an option named --list-hosts for listing hosts. Is there any option for listing host groups? Or any other way to come through?

Answer:

You can simply inspect the groups variable using the debug module:


The above is using groups.keys() to get just the list of groups. You could drop the .keys() part to see group membership as well:

Leave a Reply