What is an Inventory?
Ansible inventory is the list of servers, devices, and hosts that Ansible manages. Inventories can be static or dynamic. They may be written in INI or YAML format
Basic Inventory Example
[webservers]
web1.example.com
web2.example.com
[databases]
db1.example.com
Run:
ansible webservers -i hosts -m ping
Inventory with Variables
[webservers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11
[webservers:vars]
ansible_user=ubuntu
YAML Inventory Example
all:
children:
web:
hosts:
web1:
ansible_host: 192.168.1.10
web2:
ansible_host: 192.168.1.11
Useful Inventory Commands
List inventory:
ansible-inventory -i hosts --list
Visualize hosts:
ansible-inventory -i hosts --graph
Best Practices
- Group servers by function.
- Use group variables.
- Separate production and development inventories.
- Consider dynamic inventory for cloud environments






