controller_inventories.yml

In these files we configure the inventories for automation controller.
we will probably do this on each environment separately, as the hostnames differ.

variables

The api understands the following structure for defining inventories in controller:

{
    "name": "",
    "description": "",
    "organization": null,
    "kind": "",
    "host_filter": null,
    "variables": '{}',
    "prevent_instance_group_fallback": false
}

NOTE The "variables" variable must be specified in each definition of an inventory, the collection will
fail with an error (the default for variables in the collection is defined as a str and this must be a dict).

group_vars/all/controller_inventories.yml

Here we see an empty set for all.

---
controller_inventories_all: []
...

But you can already see that the variable name used here has the "_all" extension, so the variable will not be overridden as this is not quite a inventory.
Why we do this, will become clear in a moment.

group_vars/dev/controller_inventories.yml

As we do not configure extra inventories in development, this file is an empty set.
(We use the containerized setup version, so no need for inventories).

---
controller_inventories_dev: []
  # No extra config exists
...

Here the variable has the "_dev" extension, so the variable will not be overridden.

group_vars/prod/controller_inventories.yml

As we do not configure extra inventories in prod, this file is an empty set.

---
controller_inventories_prod: []
  # No extra config exists
...

Here the variable has the "_prod" extension, so the variable will not be overridden.

When we run a pipeline for a certain environment, the inventory structure will provide us with 2 variables: - controller_inventories_all
- controller_inventories_

We will merge these 2 variables into 1: controller_inventories and feed this to the infra.aap_configuration.controller_inventories role.
In main.yml the merge of the variables is done by this piece of code:

    - name: Set the controller vars
      ansible.builtin.set_fact:
        controller_inventories: >
          {{ controller_inventories_all |
          community.general.lists_mergeby(vars['controller_inventories_' + branch_name],
          'name', recursive=true, list_merge='append') }}

This results in the controller_inventories variable the collection needs.

Back