controller_templates.yml

In these files we configure the templates for automation controller.

The infra.aap_configuration collection expects the vaules in the variable: controller_templates. 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 templates 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 structure to define jobb_templates in controller, as exposed by the api.

{
    "name": "",
    "description": "",
    "job_type": "run",
    "inventory": null,
    "project": null,
    "playbook": "",
    "scm_branch": "",
    "forks": 0,
    "limit": "",
    "verbosity": 0,
    "extra_vars": "",
    "job_tags": "",
    "force_handlers": false,
    "skip_tags": "",
    "start_at_task": "",
    "timeout": 0,
    "use_fact_cache": false,
    "execution_environment": null,
    "host_config_key": "",
    "ask_scm_branch_on_launch": false,
    "ask_diff_mode_on_launch": false,
    "ask_variables_on_launch": false,
    "ask_limit_on_launch": false,
    "ask_tags_on_launch": false,
    "ask_skip_tags_on_launch": false,
    "ask_job_type_on_launch": false,
    "ask_verbosity_on_launch": false,
    "ask_inventory_on_launch": false,
    "ask_credential_on_launch": false,
    "ask_execution_environment_on_launch": false,
    "ask_labels_on_launch": false,
    "ask_forks_on_launch": false,
    "ask_job_slice_count_on_launch": false,
    "ask_timeout_on_launch": false,
    "ask_instance_groups_on_launch": false,
    "survey_enabled": false,
    "become_enabled": false,
    "diff_mode": false,
    "allow_simultaneous": false,
    "job_slice_count": 1,
    "webhook_service": null,
    "webhook_credential": null,
    "prevent_instance_group_fallback": false
}

group_vars/all/controller_templates.yml

Here we configure the recovery templates in all environments, so we can recover any environment, from any environment.

---
controller_templates_all:

  - name: MGT_Recover_RHAAP
    description: Restart all CaC pipelines for RHAAP
    organization: MGT
    project: MGT_recover_rhaap
    inventory: MGT_inventory
    playbook: main.yml
    job_type: run
    fact_caching_enabled: false
    credentials:
      - MGT_ansible
    ask_scm_branch_on_launch: false
    ask_tags_on_launch: false
    ask_verbosity_on_launch: false
    ask_variables_on_launch: false
    extra_vars:
    execution_environment: Gitlab Execution Environment
    survey_enabled: true
    survey_spec:
      name: ''
      description: ''
      spec:
        - question_name: Env to recover
          question_description: ''
          required: true
          type: multiplechoice
          variable: gitlab_env_branch
          min: 0
          max: 20
          default: ''
          choices:
            - dev
            - test
            - accp
            - prod
          new_question: false

...

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_templates.yml

We configure extra templates in development, this an empty set at this moment (and probably will stay empty as thisis the base configuration).

---
controller_templates_dev: []
...

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

group_vars/prod/controller_templates.yml

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

---
controller_templates_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_templates_all
- controller_templates_

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

This results in the controller_templates variable the collection needs.

Back