From 51c867729bc6d484de41d46114396c31a090691f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Fri, 12 Dec 2025 13:57:38 +0100 Subject: [PATCH] [nat64_appliance] Make ci_script usage optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the role more generic by allowing it to work outside the ci-framework context. The `cifmw.general.ci_script` module is now optional and can be disabled by setting: `cifmw_nat64_appliance_use_ci_script: false` The role defaults to using `ci_script`. Also refactored the image building logic into a separate `build_image.yml` task file for better code organization. Assisted-By: Claude Code/claude-4.5-sonnet Signed-off-by: Harald Jensås --- roles/nat64_appliance/defaults/main.yml | 4 ++ roles/nat64_appliance/tasks/build_image.yml | 60 +++++++++++++++++++ .../tasks/build_with_ci_script.yml | 28 +++++++++ .../tasks/build_with_shell.yml | 28 +++++++++ roles/nat64_appliance/tasks/main.yml | 51 +--------------- 5 files changed, 121 insertions(+), 50 deletions(-) create mode 100644 roles/nat64_appliance/tasks/build_image.yml create mode 100644 roles/nat64_appliance/tasks/build_with_ci_script.yml create mode 100644 roles/nat64_appliance/tasks/build_with_shell.yml diff --git a/roles/nat64_appliance/defaults/main.yml b/roles/nat64_appliance/defaults/main.yml index 6fdf18b8bf..94158a434d 100644 --- a/roles/nat64_appliance/defaults/main.yml +++ b/roles/nat64_appliance/defaults/main.yml @@ -47,3 +47,7 @@ cifmw_nat64_appliance_download_timeout: 600 # 10 minutes cifmw_nat64_ipv6_prefix: "2620:cf:cf:fc00::/64" cifmw_nat64_ipv6_tayga_address: "2620:cf:cf:fc00::3" + +# Set to false to use standard ansible.builtin.shell instead of cifmw.general.ci_script +# This makes the role usable outside of ci-framework context +cifmw_nat64_appliance_use_ci_script: true diff --git a/roles/nat64_appliance/tasks/build_image.yml b/roles/nat64_appliance/tasks/build_image.yml new file mode 100644 index 0000000000..3eadd7e816 --- /dev/null +++ b/roles/nat64_appliance/tasks/build_image.yml @@ -0,0 +1,60 @@ +--- +# Copyright Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Install required RPM packages + tags: + - packages + become: true + ansible.builtin.package: + name: + - python3-pip + - qemu-img + - dosfstools + - xfsprogs + state: present + +- name: Install diskimage-builder in virtualenv + tags: + - packages + ansible.builtin.pip: + virtualenv_command: "python3 -m venv" + virtualenv: "{{ cifmw_nat64_appliance_venv_dir }}" + name: + - diskimage-builder + - setuptools + +- name: Copy files to cifmw_nat64_appliance_dir + ansible.builtin.copy: + src: "{{ item }}" + dest: "{{ cifmw_nat64_appliance_workdir }}/{{ item }}" + mode: preserve + loop: + - "elements/" + - nat64-appliance.yaml + +- name: Clone edpm-image-builder (reset-bls-entries dib element) + ansible.builtin.git: + repo: https://github.com/openstack-k8s-operators/edpm-image-builder.git + dest: "{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder" + version: main + +- name: Build the nat64-appliance image using DIB (with ci_script) + when: cifmw_nat64_appliance_use_ci_script | bool + ansible.builtin.include_tasks: build_with_ci_script.yml + +- name: Build the nat64-appliance image using DIB (with shell) + when: not (cifmw_nat64_appliance_use_ci_script | bool) + ansible.builtin.include_tasks: build_with_shell.yml diff --git a/roles/nat64_appliance/tasks/build_with_ci_script.yml b/roles/nat64_appliance/tasks/build_with_ci_script.yml new file mode 100644 index 0000000000..fed170702b --- /dev/null +++ b/roles/nat64_appliance/tasks/build_with_ci_script.yml @@ -0,0 +1,28 @@ +--- +# Copyright Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Build the nat64-appliance image using DIB (with ci_script) + become: "{{ cifmw_nat64_appliance_run_dib_as_root | default(false) | bool }}" + environment: + ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements:{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder/dib/" + DIB_IMAGE_CACHE: "{{ cifmw_nat64_appliance_workdir }}/cache" + DIB_DEBUG_TRACE: '1' + cifmw.general.ci_script: + chdir: "{{ cifmw_nat64_appliance_workdir }}" + output_dir: "{{ cifmw_nat64_appliance_basedir }}/artifacts" + creates: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2" + script: "{{ cifmw_nat64_appliance_venv_dir }}/bin/diskimage-builder nat64-appliance.yaml {{ extra_args | default('') }}" + executable: "/bin/bash" diff --git a/roles/nat64_appliance/tasks/build_with_shell.yml b/roles/nat64_appliance/tasks/build_with_shell.yml new file mode 100644 index 0000000000..9dd5eee208 --- /dev/null +++ b/roles/nat64_appliance/tasks/build_with_shell.yml @@ -0,0 +1,28 @@ +--- +# Copyright Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Build the nat64-appliance image using DIB (with shell) + become: "{{ cifmw_nat64_appliance_run_dib_as_root | default(false) | bool }}" + environment: + ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements:{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder/dib/" + DIB_IMAGE_CACHE: "{{ cifmw_nat64_appliance_workdir }}/cache" + DIB_DEBUG_TRACE: '1' + ansible.builtin.shell: | + {{ cifmw_nat64_appliance_venv_dir }}/bin/diskimage-builder nat64-appliance.yaml {{ extra_args | default('') }} + args: + chdir: "{{ cifmw_nat64_appliance_workdir }}" + creates: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2" + executable: /bin/bash diff --git a/roles/nat64_appliance/tasks/main.yml b/roles/nat64_appliance/tasks/main.yml index 24ba0861e7..c30669fb1a 100644 --- a/roles/nat64_appliance/tasks/main.yml +++ b/roles/nat64_appliance/tasks/main.yml @@ -32,56 +32,7 @@ - name: Build NAT64 appliance image from source when: - cifmw_nat64_appliance_image_url | length == 0 - block: - - name: Install required RPM packages - tags: - - packages - become: true - ansible.builtin.package: - name: - - python3-pip - - qemu-img - - dosfstools - - xfsprogs - state: present - - - name: Install diskimage-builder in virtualenv - tags: - - packages - ansible.builtin.pip: - virtualenv_command: "python3 -m venv" - virtualenv: "{{ cifmw_nat64_appliance_venv_dir }}" - name: - - diskimage-builder - - setuptools - - - name: Copy files to cifmw_nat64_appliance_dir - ansible.builtin.copy: - src: "{{ item }}" - dest: "{{ cifmw_nat64_appliance_workdir }}/{{ item }}" - mode: preserve - loop: - - "elements/" - - nat64-appliance.yaml - - - name: Clone edpm-image-builder (reset-bls-entries dib element) - ansible.builtin.git: - repo: https://github.com/openstack-k8s-operators/edpm-image-builder.git - dest: "{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder" - version: main - - - name: Build the nat64-appliance image using DIB - become: "{{ cifmw_nat64_appliance_run_dib_as_root | default(false) | bool }}" - environment: - ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements:{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder/dib/" - DIB_IMAGE_CACHE: "{{ cifmw_nat64_appliance_workdir }}/cache" - DIB_DEBUG_TRACE: '1' - cifmw.general.ci_script: - chdir: "{{ cifmw_nat64_appliance_workdir }}" - output_dir: "{{ cifmw_nat64_appliance_basedir }}/artifacts" - creates: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2" - script: "{{ cifmw_nat64_appliance_venv_dir }}/bin/diskimage-builder nat64-appliance.yaml {{ extra_args | default('') }}" - executable: "/bin/bash" + ansible.builtin.include_tasks: build_image.yml - name: Download pre-built NAT64 appliance image when: