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: