Skip to content

Creating an ansible inventory

The inventory is a file that contains a list of hosts, groups and optionally variables. The inventory file can be a YAML file or an INI file. This tutorial uses YAML format.

Creating the inventory

This is an example inventory file. It contains 3 hosts and 1 group. The group webserver contains only server2.

inventory.yml
all:
  vars:
    my_variable: "Hello World"
  hosts:
    server1:
    server2:
    server3:
  children:
    webserver:
      hosts:
        server2:

The inventory always has a global group called all and there are 3 sub groups

  • hosts a list of hosts
  • vars a list of variables
  • children a list of child groups with their members.

Configure ansible to use the inventory

A file called ansible.cfg in your working directory is required to reference the inventory file. The file should look like this:

ansible.cfg
[defaults]
inventory = ./inventory.yml