Is there a way to use the Ansible Python API to get a list of hosts from a given inventory file / group combination?
For example, our inventory files are split up by service type:
[dev:children]
dev_a
dev_b
[dev_a]
my.host.int.abc.com
[dev_b]
my.host.int.xyz.com
[prod:children]
prod_a
prod_b
[prod_a]
my.host.abc.com
[prod_b]
my.host.xyz.com
Can I use ansible.inventory
in some way to pass in a specific inventory file, and the group I want to act on, and have it return a list of hosts that match?
Do the same trick from before, but instead of all
, pass the group name you want to list:
ansible (group name here) -i (inventory file here) --list-hosts