Inventory Management
Document Control
TODO:
- Overall structure.
- Initial draft complete
- Testing
- Ready
INI Inventory File
Example inventory
[web_group] web01 web02 [db_group] db01 ansible_host = 192.168.0.200 [myapp:children] web_group db_group [web_group:vars] apache_port = 80
$ ansible-inventory -i hosts --graph @all: |--@myapp: | |--@db_group: | | |--db01 | |--@web_group: | | |--web01 | | |--web02 |--@ungrouped:
YAML Inventory File
See YAML file as an inventory source
--- all: children: local: vars: ansible_connection: local hosts: localhost: {}
You can use the ansible-inventory --list --yaml
to convert a INI inventory.
Dynamic Inventory
This is especially useful when dealing with a cloud provider or a large pool of servers, or connecting to a Configuration Management Database (CMDB). They are executable files or scripts.
Inventory Directory
You can also set up a directory with multiple inventory files. This is especially useful when you wish to spearate between environments (ex: dev, test, staging, prod) or mix static and dynamic inventories.
Create a directory called inventory
and place a line in your ansible.cfg
: inventory = ./inventory
.
example
Example command
with shell, yaml and output
--- all: children: local: vars: ansible_connection: local hosts: localhost: {}
--- all: children: centos: hosts: centos8: {} centos7: {} fedora: hosts: fedora31: {} rhel: hosts: rhel81: {}
Last update: 2020-01-19