Bookmark this page

Chapter 7.  Managing Advanced Inventories

Abstract

Goal

Manage inventories that are generated dynamically from scripts or the automation controller smart inventory feature.

Objectives
  • Import existing static inventory files managed in a Git repository into automation controller.

  • Create a dynamic inventory that uses an inventory plug-in to set hosts and host groups.

  • Create a smart inventory that is dynamically constructed from the other inventories on your automation controller using a filter.

Sections
  • Importing External Static Inventories (and Guided Exercise)

  • Configuring Dynamic Inventory Plug-ins (and Quiz)

  • Filtering Hosts with Smart Inventories (and Guided Exercise)

Lab
  • Managing Advanced Inventories

Importing External Static Inventories

Objectives

  • Import existing static inventory files managed in a Git repository into automation controller.

Importing Existing Static Inventories

If you are adding an existing Ansible project that you have been managing from a traditional control node into automation controller, you might already have a large static inventory file for that project. It can be inconvenient to add that static inventory manually through the web UI. You might also want to continue to manage that static inventory outside of automation controller rather than through the web UI. A number of ways exist to handle these situations.

One of the most effective solutions is to configure automation controller to retrieve a static inventory file from an existing automation controller project. This approach enables you to manage changes to the inventory (and inventory variables) just like changes to other files under version control. Although possible, you should avoid using the web UI to make changes to this type of inventory because automation does not push changes back to your version control system. When you make a change to your source control repository that affects the inventory, you need to synchronize both the associated project and inventory before automation controller recognizes the changes.

Storing an Inventory in a Project

Automation controller can use inventory files that you manage in a source code management (SCM) repository. You can continue to store your inventory in a Git repository, and use commits, pull requests, and other features of Git or your repository server to manage updates. You can also use any other type of SCM that is supported by projects in automation controller.

To configure this functionality, start by setting up a project that points to your Git repository. This is done in exactly the same way as when you are setting up a project to be part of a job template. Specify the Source Control Type (such as Git) and Source Control URL of the repository containing the inventory file or files. You also need to specify the Source Control Credential that contains the authentication information for that repository. You can specify a particular branch, tag, or commit to use, and whether the contents of the project should update the revision on launch like any other project.

Figure 7.1: Configuring Git-based projects

After you have set up the project, you can configure the inventory in automation controller. Create the inventory normally and open it for editing. Click Sources, and then click Add to add a new source.

On the Create new source page, give the source a name and then select a source. Selecting the SourceSourced from a Project source exposes extra fields on the page. Specify the Project that contains your inventory. Select the inventory file from the Inventory file list, or enter the file name if it does not appear.

You can enter an SCM credential in the Credential field if one is needed to access the project’s Git repository. You can also select the Update on project update checkbox to refresh the inventory after every project update that involves a Git revision update. Finally, you can save the changes and synchronize the inventory with the project.

Figure 7.2: Inventory sourced from a project

References

For more information about adding inventories to automation controller, refer to the Automation Controller User Guide at https://docs.ansible.com/automation-controller/latest/html/userguide/inventories.html#add-a-new-inventory

Revision: do467-2.2-08877c1