Module 3: Creating an Inventory

A guide to managing hosts and groups the easy way by creating and populating an inventory in automation controller.


Lab Briefing

This section provides an overview of inventories in Ansible Automation Platform.

What are Inventories?

An inventory defines the hosts and groups of hosts upon which commands, modules, and tasks in a playbook operate. It is the fundamental way that Ansible and the automation controller keep track of what systems to manage.

Inventories list view in automation controller

In this challenge, you will be creating a new inventory, adding hosts to it, and then creating a group to organize those hosts.

Creating a new inventory

Lab Guide

An inventory is a collection of hosts against which jobs (like playbooks) may be launched. This is the same concept as an Ansible inventory file, but with a powerful UI and additional features.

Inventories are divided into groups, and these groups contain the actual hosts. Hosts can be referenced by their IP addresses or their hostnames and can be sourced manually or dynamically from a cloud provider.

The credentials for the automation controller are:

  • Username: admin

  • Password: ansible123!

Task 1: Create the Inventory

First, you will create a new, empty inventory to hold your managed nodes.

  1. Navigate to the Inventories page.

    In the left navigation menu, go to Automation ExecutionInfrastructureInventories.

  2. Create a new inventory.

    Click the blue Create inventory button and select Create inventory from the dropdown.

  3. Enter the inventory details.

    Fill out the form with the following information:

    • Name: Lab-Inventory

    • Organization: Default

  4. Save the inventory.

    Click the blue Create inventory button.

Task 2: Add Hosts to the Inventory

Now you will manually add two hosts to your new inventory.

If you are not already on the Lab-Inventory details page, navigate back to it by clicking its name in the inventory list.
  1. Navigate to the Hosts tab.

    Within the Lab-Inventory, click the Hosts tab.

  2. Create the first host.

    Click the blue Create host button. In the Name field, enter node1. Leave all other fields as they are and click Create host.

  3. Create the second host.

    Navigate back to the main hosts list by clicking the < Back to Hosts breadcrumb link. Repeat the steps above to create a second host named node2.

Task 3: Create a Group

Groups are used to organize hosts and apply variables to multiple hosts at once.

  1. Navigate to the Groups tab.

    Go back to the main Lab-Inventory page and click the Groups tab.

  2. Create a new group.

    Click the blue Create group button.

  3. Name the group.

    In the Name field, enter web.

    Unlike in a static inventory file, you do not need to use brackets [] around the group name in the UI.
  4. Save the group.

    Click the blue Create group button.

Task 4: Add Hosts to the Group

Finally, you will associate your two hosts with the new web group.

  1. Navigate to the Hosts tab for the group.

    Inside the web group you just created, click the Hosts tab.

  2. Add existing hosts.

    Click the blue Add existing host button.

  3. Select the hosts.

    In the pop-up window, select the checkbox for both node1 and node2, then click Add hosts.

  4. Verify the association.

    You should now see both node1 and node2 listed in the Hosts tab for the web group.


Controller as Code Alternative

Everything you just created through the UI — the inventory, hosts, and group — can be defined as declarative YAML and applied automatically using the infra.aap_configuration collection.

YAML Definition

The following variable file (controller-as-code/configs/module-03/controller_objects.yml) defines the same objects:

---
controller_inventories:
  - name: Lab-Inventory
    organization: Default

controller_hosts:
  - name: node1
    inventory: Lab-Inventory
    state: present
  - name: node2
    inventory: Lab-Inventory
    state: present

controller_groups:
  - name: web
    inventory: Lab-Inventory
    hosts:
      - node1
      - node2

The dispatch role in infra.aap_configuration automatically creates the objects in the correct dependency order: inventory first, then hosts, then groups.


Next Steps

Press the blue Next button below to proceed to the next challenge.

Troubleshooting

If you have encountered an issue or have noticed something not quite right, please open an issue on GitHub.