controller_inventory_sources.yml

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

The infra.aap_configuration collection expects the vaules in the variable: controller_inventory_sources. As we intend to configure everything just once, we spit the set of vars into the environments and join the lists in the main.yml, before calling the collection. If there are no inventory_sources defined, do not add this file. If you do, ensure the file is present in all branches, with the correct content, described below.

variables

The api understands the following structure for defining inventory sources in controller:

{
    "name": "",
    "description": "",
    "source": null,
    "source_path": "",
    "source_vars": '{}',
    "scm_branch": "",
    "credential": null,
    "enabled_var": "",
    "enabled_value": "",
    "host_filter": "",
    "overwrite": false,
    "overwrite_vars": false,
    "timeout": 0,
    "verbosity": 1,
    "limit": "",
    "execution_environment": null,
    "inventory": null,
    "update_on_launch": false,
    "update_cache_timeout": 0,
    "source_project": null
}

NOTE The "source _vars" variable must be specified on each definition o an inventory_source,
or else the collection will fail (the default in the role is specified as str and it must be a dict).

group_vars/all/controller_inventory_sources.yml

Here we see an empty set for all.

---
controller_inventory_sources_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_inventory_sources.yml

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

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

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

group_vars/prod/controller_inventory_sources.yml

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

---
controller_inventory_sources_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_inventory_sources_all
- controller_inventory_sources_

We will merge these 2 variables into 1: controller_inventory_sources and feed this to the infra.aap_configuration.controller_inventory_sources 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_inventory_sources: >
          {{ controller_inventory_sources_all |
          community.general.lists_mergeby(vars['controller_inventory_sources_' + branch_name],
          'name', recursive=true, list_merge='append') }}

This results in the controller_inventory_sources variable the collection needs.

Back