From 51cee892ff458aa3427f02a55f173eed8e396872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Jeanneret?= Date: Thu, 4 Apr 2024 16:35:47 +0200 Subject: [PATCH 1/2] Add a new parameter to inject extravars in nested plays It may happen we want to inject extra ansible variables in the nested calls to ansible-playbook. The new `cifmw_reproducer_play_extravars` parameter allows to list any "extra-vars" you want. By leveraging it, you can for instance inject a crafted scenario file listing a series of hooks directly in the application deployment. --- roles/reproducer/README.md | 1 + roles/reproducer/defaults/main.yml | 1 + .../tasks/configure_architecture.yml | 22 ++++++++--------- roles/reproducer/tasks/main.yml | 24 +++++++++---------- roles/reproducer/templates/script.sh.j2 | 16 +++++++++++++ 5 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 roles/reproducer/templates/script.sh.j2 diff --git a/roles/reproducer/README.md b/roles/reproducer/README.md index b2ea6e352d..c64c1a5de9 100644 --- a/roles/reproducer/README.md +++ b/roles/reproducer/README.md @@ -7,6 +7,7 @@ None ## Parameters * `cifmw_reproducer_basedir`: (String) Base directory. Defaults to `cifmw_basedir`, which defaults to `~/ci-framework-data`. * `cifmw_reproducer_compute_repos`: (List[mapping]) List of yum repository that must be deployed on the compute nodes during their creation. Defaults to `[]`. +* `cifmw_reproducer_play_extravars`: (List[string]) List of extra-vars you want to pass down to the EDPM deployment playbooks. Defaults to `[]`. * `cifmw_reproducer_kubecfg`: (String) Path to the CRC kubeconfig file. Defaults to the image_local_dir defined in the cifmw_libvirt_manager_configuration dict. * `cifmw_reproducer_repositories`: (List[mapping]) List of repositories you want to synchronize from your local machine to the ansible controller. * `cifmw_reproducer_run_job`: (Bool) Run actual CI job. Defaults to `true`. diff --git a/roles/reproducer/defaults/main.yml b/roles/reproducer/defaults/main.yml index 3641eddf7f..1844337e30 100644 --- a/roles/reproducer/defaults/main.yml +++ b/roles/reproducer/defaults/main.yml @@ -30,3 +30,4 @@ cifmw_reproducer_hp_rhos_release: false cifmw_reproducer_dnf_tweaks: [] cifmw_reproducer_compute_repos: [] cifmw_reproducer_repositories_path: "src" +cifmw_reproducer_play_extravars: [] diff --git a/roles/reproducer/tasks/configure_architecture.yml b/roles/reproducer/tasks/configure_architecture.yml index c536d77e60..e9fd23b174 100644 --- a/roles/reproducer/tasks/configure_architecture.yml +++ b/roles/reproducer/tasks/configure_architecture.yml @@ -3,21 +3,21 @@ delegate_to: controller-0 block: - name: Push script - ansible.builtin.copy: + vars: + run_directory: "src/github.com/openstack-k8s-operators/ci-framework" + exports: + ANSIBLE_LOG_PATH: "~/ansible-deploy-architecture.log" + default_extravars: + - "@~/reproducer-variables.yml" + - "@~/openshift-environment.yml" + extravars: "{{ cifmw_reproducer_play_extravars }}" + playbook: "deploy-edpm.yml" + ansible.builtin.template: dest: "/home/zuul/deploy-architecture.sh" + src: "script.sh.j2" mode: "0755" owner: "zuul" group: "zuul" - content: |- - #!/bin/bash - set -e - pushd src/github.com/openstack-k8s-operators/ci-framework - export ANSIBLE_LOG_PATH="~/ansible-deploy-architecture.log" - ansible-playbook -i ~/ci-framework-data/artifacts/zuul_inventory.yml \ - -e @~/reproducer-variables.yml \ - -e @~/openshift-environment.yml \ - deploy-edpm.yml --flush-cache $@ - popd - name: Rotate some logs tags: diff --git a/roles/reproducer/tasks/main.yml b/roles/reproducer/tasks/main.yml index d3e8440d31..f78d1bf604 100644 --- a/roles/reproducer/tasks/main.yml +++ b/roles/reproducer/tasks/main.yml @@ -194,19 +194,19 @@ - name: Prepare ci-like EDPM deploy delegate_to: controller-0 - ansible.builtin.copy: + vars: + run_directory: "src/github.com/openstack-k8s-operators/ci-framework" + exports: + ANSIBLE_LOG_PATH: "~/ansible-deploy-edpm.log" + default_extravars: + - "@scenarios/centos-9/base.yml" + - "@scenarios/centos-9/edpm_ci.yml" + - "cifmw_openshift_password='{{ cifmw_openshift_password }}'" + extravars: "{{ cifmw_reproducer_play_extravars }}" + playbook: "deploy-edpm.yml" + ansible.builtin.template: dest: "/home/zuul/deploy-edpm.sh" + src: "script.sh.j2" mode: "0755" owner: "zuul" group: "zuul" - content: |- - #!/bin/bash - set -e - pushd src/github.com/openstack-k8s-operators/ci-framework - export ANSIBLE_LOG_PATH="~/ansible-deploy-edpm.log" - ansible-playbook deploy-edpm.yml \ - -e @scenarios/centos-9/base.yml \ - -e @scenarios/centos-9/edpm_ci.yml \ - -e cifmw_openshift_password="{{ cifmw_openshift_password }}" \ - --flush-cache $@ - popd diff --git a/roles/reproducer/templates/script.sh.j2 b/roles/reproducer/templates/script.sh.j2 new file mode 100644 index 0000000000..4bf2990c40 --- /dev/null +++ b/roles/reproducer/templates/script.sh.j2 @@ -0,0 +1,16 @@ +#!/bin/bash +set -e +pushd {{ run_directory}} +{% for export in exports | dict2items %} +export {{ export.key }}="{{ export.value }}" +{% endfor %} + +ansible-playbook -i ~/ci-framework-data/artifacts/zuul_inventory.yml \ +{% for extravar in default_extravars %} + -e {{ extravar }} \ +{% endfor %} +{% for extravar in extravars %} + -e {{ extravar }} \ +{% endfor %} + {{ playbook }} --flush-cache $@ +popd From 59b550e76ec5a12353b52c8ad6590520afcccb0e Mon Sep 17 00:00:00 2001 From: John Fulton Date: Thu, 4 Apr 2024 14:01:00 -0400 Subject: [PATCH 2/2] Support cifmw_ceph_client_cluster overrides If a user overrides `cifmw_cephadm_cluster`, then the Ceph cluster name is something other than the default of "ceph" and the keyring and conf files are named from the override. However, without this patch the `cifmw_ceph_client` role does not respect this override. Update the role and the call to it from the Ceph playbook so that files consumed by Ceph clients get a name consistent with the server. This feature is useful for deployments with more than one Ceph server. Signed-off-by: John Fulton --- playbooks/ceph.yml | 1 + roles/cifmw_ceph_client/templates/k8s_ceph_secret.yml.j2 | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/playbooks/ceph.yml b/playbooks/ceph.yml index df6b8f730d..59c366d773 100644 --- a/playbooks/ceph.yml +++ b/playbooks/ceph.yml @@ -398,6 +398,7 @@ cifmw_ceph_client_fetch_dir: /tmp cifmw_ceph_client_k8s_secret_name: ceph-conf-files cifmw_ceph_client_k8s_namespace: openstack + cifmw_ceph_client_cluster: "{{ cifmw_cephadm_cluster | default('ceph') }}" pre_tasks: # end_play will end this current playbook and go the the next # imported play. diff --git a/roles/cifmw_ceph_client/templates/k8s_ceph_secret.yml.j2 b/roles/cifmw_ceph_client/templates/k8s_ceph_secret.yml.j2 index 8c74d4a53b..10ef553d97 100644 --- a/roles/cifmw_ceph_client/templates/k8s_ceph_secret.yml.j2 +++ b/roles/cifmw_ceph_client/templates/k8s_ceph_secret.yml.j2 @@ -1,8 +1,8 @@ --- apiVersion: v1 data: - ceph.client.openstack.keyring: {{ cifmw_ceph_client_key_file_b64.content }} - ceph.conf: {{ cifmw_ceph_client_conf_file_b64.content }} + {{ cifmw_ceph_client_cluster | default('ceph') }}.client.openstack.keyring: {{ cifmw_ceph_client_key_file_b64.content }} + {{ cifmw_ceph_client_cluster | default('ceph') }}.conf: {{ cifmw_ceph_client_conf_file_b64.content }} kind: Secret metadata: name: {{ cifmw_ceph_client_k8s_secret_name }}