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?
Group variables are a convenient way to apply variables to multiple hosts at once. Before executing, however, Ansible always flattens variables, including inventory variables, to the host level. If a host is a member of multiple groups, Ansible reads variable values from all of those groups.
We can create directories under the group named directory, it will read all the files under these directories in lexicographical. If there is some value which is true for your environment and for every server, the variable containing that value should be defined under /etc/ansible/group_vars/all file.
do-ansible-inventory is a tool that generates an Ansible inventory file with your DigitalOcean Droplets. It is an alternative to dynamic inventories as you can run do-ansible-inventory once and receive a static inventory file that you can use anywhere, copy, or modify.
You can simply inspect the groups
variable using the debug
module:
ansible localhost -m debug -a 'var=groups.keys()'
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:
ansible localhost -m debug -a 'var=groups'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With