diff --git a/roles/install_yamls/README.md b/roles/install_yamls/README.md index d6f1c63275..ee38655e7e 100644 --- a/roles/install_yamls/README.md +++ b/roles/install_yamls/README.md @@ -1,9 +1,11 @@ # install_yamls + An ansible role wrapper around [install_yamls](https://github.com/openstack-k8s-operators/install_yamls) Makefile. It dynamically creates `install_yamls_makes` role, which can be reused within [the CI Framework and other projects](https://github.com/rdo-infra/rdo-jobs/blob/39d0647cbb20abe3aaf2baad134a0e09473e1c54/playbooks/data_plane_adoption/ci_framework_install_yamls.yaml#L5-L24). It contains a set of playbooks to deploy podified control plane. ## Parameters + * `cifmw_install_yamls_envfile`: (String) Environment file containing all the Makefile overrides. Defaults to `install_yamls`. * `cifmw_install_yamls_out_dir`: (String) `install_yamls` output directory to store generated output. Defaults to `{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts"`. * `cifmw_install_yamls_vars`: (Dict) A dict containing Makefile overrides. @@ -13,9 +15,17 @@ It contains a set of playbooks to deploy podified control plane. * `cifmw_install_yamls_checkout_openstack_ref`: (String) Enable the checkout from openstack-operator references when cloning operator's repository using install_yamls make targets. Defaults to `"true"` +## cifmw_install_yamls_vars patching + +This role makes possible to define a base `cifmw_install_yamls_vars` and +patch its values afterwards by defining variables named like `^cifmw_install_yamls_vars_patch.*` +that will be combined on top of the original `cifmw_install_yamls_var` after sorting them by name. + ## Use case + This module uses [a custom plugin](https://github.com/openstack-k8s-operators/ci-framework/blob/main/plugins/modules/generate_make_tasks.py) created to generate the role with tasks from Makefile. The created role directory contains multiple task files, similar to + ```YAML --- - name: Debug make_crc_storage_env @@ -40,6 +50,7 @@ The created role directory contains multiple task files, similar to ``` The role can be imported and tasks can be executed like this + ```YAML - name: Prepare storage in CRC vars: diff --git a/roles/install_yamls/molecule/default/converge.yml b/roles/install_yamls/molecule/default/converge.yml index 6c5f6f8036..78ba7be9d2 100644 --- a/roles/install_yamls/molecule/default/converge.yml +++ b/roles/install_yamls/molecule/default/converge.yml @@ -20,6 +20,7 @@ vars: cifmw_install_yamls_vars: namespace: foobar + openstack_ctlplane: controlplane-yaml-file.yaml ansible_user_dir: "{{ lookup('env', 'HOME') }}" cifmw_install_yamls_repo: "{{ ansible_user_dir }}/src/github.com/openstack-k8s-operators/install_yamls" zuul: @@ -41,14 +42,29 @@ short_name: service-telemetry-operator name: infrawatch/service-telemetry-operator src_dir: src/github.com/infrawatch/service-telemetry-operator - roles: - - role: "install_yamls" - tasks: + - name: Add install_yamls vars overrides + ansible.builtin.set_fact: + cifmw_install_yamls_vars_patch_01_patch: + namespace: patched + cifmw_install_yamls_vars_patch_02_patch: + namespace: patched2 + infra_img: quay.io/openstack-k8s-operators/infra-operator-index:dummy + + - name: Call role under test + ansible.builtin.include_role: + name: "install_yamls" + - name: Ensure we get cifmw_install_yamls_environment fact ansible.builtin.assert: that: - cifmw_install_yamls_environment is defined + - cifmw_install_yamls_environment.OPENSTACK_CTLPLANE is defined + - cifmw_install_yamls_environment.OPENSTACK_CTLPLANE == cifmw_install_yamls_vars.openstack_ctlplane + - cifmw_install_yamls_environment.NAMESPACE is defined + - cifmw_install_yamls_environment.NAMESPACE == cifmw_install_yamls_vars_patch_02_patch.namespace + - cifmw_install_yamls_environment.INFRA_IMG is defined + - cifmw_install_yamls_environment.INFRA_IMG == cifmw_install_yamls_vars_patch_02_patch.infra_img - name: Gather some file data register: make_files diff --git a/roles/install_yamls/tasks/main.yml b/roles/install_yamls/tasks/main.yml index fc90ce7a2d..4d87716b74 100644 --- a/roles/install_yamls/tasks/main.yml +++ b/roles/install_yamls/tasks/main.yml @@ -33,18 +33,39 @@ name: install_yamls tasks_from: zuul_set_operators_repo.yml +- name: Compute the cifmw_install_yamls_vars final value + tags: + - bootstrap + vars: + _cifmw_install_yamls_vars_patches: >- + {{ + hostvars[inventory_hostname] | + dict2items | + selectattr("key", "match", + "^cifmw_install_yamls_vars_patch.*") | + sort(attribute='key') | + map(attribute='value') | + list + }} + ansible.builtin.set_fact: + _install_yamls_override_vars: >- + {{ + _install_yamls_override_vars | default({}) | + combine(item, recursive=True) + }} + loop: "{{ [cifmw_install_yamls_vars| default({})] + _cifmw_install_yamls_vars_patches }}" + - name: Set environment override cifmw_install_yamls_environment fact tags: - bootstrap vars: - install_yamls_override_vars: "{{ cifmw_install_yamls_vars| default({}) }}" install_yamls_operators_repos: "{{ cifmw_install_yamls_operators_repo | default({}) }}" ansible.builtin.set_fact: cifmw_install_yamls_environment: >- {{ - install_yamls_override_vars.keys() | + _install_yamls_override_vars.keys() | map('upper') | - zip(install_yamls_override_vars.values()) | + zip(_install_yamls_override_vars.values()) | items2dict(key_name=0, value_name=1) | combine({ 'OUT': cifmw_install_yamls_manifests_dir,