Maintaining an Inventory

Maintaining an Inventory#

Using INI or YAML files#

Using INI files#
1 server01.example.org
2 server02.example.org
3 server03.example.org
4 server04.example.org
5 server05.example.org
6 server06.example.org
Using YAML files#
1 ---
2 all:
3   hosts:
4     server01.example.org:
5     server02.example.org:
6     server03.example.org:
7     server04.example.org:
8     server05.example.org:
9     server06.example.org:
 1 server01.example.org
 2 server02.example.org
 3
 4 [web]
 5 server03.example.org
 6 server04.example.org
 7
 8 [db]
 9 server05.example.org
10 server06.example.org
Using YAML files#
 1 ---
 2 all:
 3   hosts:
 4     server01.example.org:
 5     server02.example.org:
 6   children:
 7     web:
 8       hosts:
 9         server03.example.org:
10         server04.example.org:
11     db:
12       hosts:
13         server05.example.org:
14         server06.example.org:
Using a single inventory file#
 ansible-playbook site.yml -i staging
Using multiple inventory files#
 ansible-playbook site.yml -i staging.yml -i production.yml

Inventory parameters#

  • ansible_port

  • ansible_user

  • ansible_host

  • ansible_connection

  • ansible_password

  • ansible_python_interpreter

Using YAML files#
 1 ---
 2 all:
 3   hosts:
 4     server01.example.org:
 5     server02.example.org:
 6   children:
 7     web:
 8       hosts:
 9         server03.example.org:
10         server04.example.org:
11     db:
12       hosts:
13         server05.example.org:
14         server06.example.org:
15   vars:
16     ansible_port: 2222
17     ansible_user: deploy
18     ansible_python_interpreter: /usr/bin/python3