Ansible inventory
130 words
Table of Contents
The inventory can be:
- a file
- a directory
- an executable
The inventory location is mentioned in the ansible.cfg file with the inventory keyword:
[defaults]
inventory = /etc/ansible/hosts
format of an inventory file #
The inventory:
- file is an ini style file with group names as section headers.
- directory is a directory with a collection of such
- executable outputs a json type output
The inventory accepts regular expressions, ranges are mentioned as [0:9] not as [0-9] and IP address format does not accept normal like 10.0.0.0/24.
Example #1:
[group1]
server1 ansible_connection=local
server2
[group2]
server3
server4
192.168.[0:1].[128:250]
[group3:children]
group1
group2
Warning
In the inventory directory the files and executables are sourced : in order. This means if a groups children aren’t mentioned yet the run will fail.
note
var files vs include_vars