How to build your inventory — Ansible Documentation
docs.ansible.com › ansible › latestDec 21, 2021 · Ansible works against multiple managed nodes or “hosts” in your infrastructure at the same time, using a list or group of lists known as inventory. Once your inventory is defined, you use patterns to select the hosts or groups you want Ansible to run against. The default location for inventory is a file called /etc/ansible/hosts.
How can I get a list of hosts from an Ansible inventory file ...
newbedev.com › how-can-i-get-a-list-of-hosts-fromDo 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. For me following worked. from ansible.parsing.dataloader import DataLoader from ansible.inventory.manager import InventoryManager if __name__ == '__main__': inventory_file_name = 'my.inventory' data_loader = DataLoader () inventory = InventoryManager (loader = data_loader, sources= [inventory_file_name]) print (inventory.get_groups_dict ...