Scenario:
I want to use different roles in the Collection infra.controller_configuration to configure AAP - Ansible Automation Platform.
If possible I would like to use a structure as below for defining the variables of the objects that I want to create:
$ tree
.
|-- credentials
| |-- credential_1.yml
| |-- credential_2.yml
|-- inventories
| |-- inventory_1.yml
| |-- inventory_2.yml
|-- job_templates
| |-- job_template_1.yml
| |-- job_template_2.yml
|-- projects
| |-- project_1.yml
| |-- project_2.yml
It seems like the default behaviour for the roles in the infra.controller_configuration collection is to use one file as input for the configuration. Of course we can concatenate the configuration files and just use one variable file per role. But from a configuration perspective I think it is easier to maintain a structure were each object corresponds to a single file. Most files are quite small but if you look at for instance job_templates which includes a survey, these files can be big quite big. And if you have +100 job_templates it is not so nice to manage them in a single file.
Is it possible to use the roles to configure AAP using this kind of variable structure and have it to parse all files relevant per role?
Can you run a role in a loop where it is parsing each variable file as input?
I was first looking into include_vars to see if there was a way to merge multiple variable files and get a concatenated variable.
If you take the the two inventory files as an example:
$ cat inventories/inventory_1.yml
---
controller_inventories:
- name: "Inventory1"
description: "Test"
organization: "Org1"
...
$ cat inventories/inventory_2.yml
---
controller_inventories:
- name: "Inventory2"
description: "Test"
organization: "Org1"
...
The goal is either to be able to merge them so you get this as output:
---
controller_inventories:
- name: "Inventory1"
description: "Test"
organization: "Org1"
- name: "Inventory2"
description: "Test"
organization: "Org1"
...
This can be used as input for role infra.controller_configuration.inventories:
The official docs suggest that you can do like this to import vars:
pre_tasks:
- name: Include vars from controller_configs directory
ansible.builtin.include_vars:
dir: ./yaml
ignore_files: [controller_config.yml.template]
extensions: ["yml"]
When I use it the result is that I only get the vars in the second inventory file:
ok: [bastion] => {
"ansible_facts": {
"controller_inventories": [
{
"description": "Test",
"name": "Inventory2",
"organization": "Org1"
}
]
},
"ansible_included_var_files": [
"/orgs/org1/inventories/inventory_1.yml",
"/orgs/org1/inventories/inventory_2.yml"
],
"changed": false
}
Any suggestions for how to move forward with this is very appriciated!
Testing on RHEL8 server using:
ansible-playbook [core 2.15.5]
config file = /etc/ansible/ansible.cfg
ansible python module location = /usr/lib/python3.9/site-packages/ansible
executable location = /bin/ansible-playbook
python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.9)
jinja version = 3.1.2
libyaml = True