Bookmark this page

Creating Inventories Using YAML

Objectives

After completing this section, you should be able to:

  • Manage hosts and host groups in inventories using a dynamic inventory.

  • Use the ansible-inventory command to validate data provided by dynamic inventories.

Reviewing What Inventories Provide

Ansible looks up host and host group information in an inventory. The names in the inventory are used by plays to determine on which hosts and host groups they should run. They are also used to determine the values of host variables and group variables, some of which might change how Ansible connects or authenticates to those managed hosts.

You have seen how to create and edit inventories as files, and how the ansible, ansible-inventory, and ansible-playbook commands locate inventory files. You saw cases, for instance, where the -i option is used to have the ansible and ansible-* programs use a particular inventory file.

Describing Static Inventories

Supported formats for inventory files include INI and YAML.

# INI format - filename: inventory
[servers]
server1
server2

[leafs]
leaf1
leaf2

[spines]
spine1
spine2

[network:children]
leafs
spines
# YAML format - filename: inventory.yml
servers:
  hosts:
    server1:
    server2:

spines:
  hosts:
    spine1:
    spine2:

leafs:
  hosts:
    leaf1:
    leaf2
Revision: do457-2.5-4693601