Skip to content

Latest commit

 

History

History
85 lines (53 loc) · 2.06 KB

inventory.rst

File metadata and controls

85 lines (53 loc) · 2.06 KB

Inventory

Inventory directory

Whatever directory the :ref:`inventory-file` is in.

Inventory file

Default
/etc/ansible/hosts
Change

set ANSIBLE_HOSTS in environment

ansible-playbook -i <inventoryfile> ...

set :ref:`hostfile` in configuration

Syntax
.ini file, except initial lines don't need to be in a section

The inventory file is basically a list of hostnames or IP addresses, one per line. Can include port with hostname:port or address:port.

Ranges: Including [m:n] in a line will repeat the line for every value from m through n. m and n can be numbers or letters.

Host :ref:`variables`: Can specify per-host options after hostname on the same line. E.g. jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50. See also :ref:`variables-files`.

Group :ref:`variables`: add [groupname:vars] section and put var definitions in it, one per line. See also :ref:`variables-files`.

Groups of groups: add [newgroupname:children] and put other group names in it, one per line.

Dynamic inventory

If the inventory file is executable, then instead of reading it as a .ini file, Ansible will run it and use its output - but the output is not in the same format as a non-executable .ini file would be. See the docs for all the details.

Host specs

You can build :ref:`host-conditionals` with a host spec, also called a pattern in Ansible.

All hosts:
* or all
One specific host:
hostname or ipaddress
One group:
groupname
Wildcard globs:
*.example.com or 127.0.*.3
Regexes:
~(web|db).example.com

Expressions:

spec1:spec2 - all hosts matched by spec1 or spec2

spec1:!spec2 - hosts matched by spec1, except those matched by spec2

spec1:&spec - hosts matched by both spec1 and spec2