Skip to content

Commit 8bd3f89

Browse files
committed
[nat64_appliance] Make ci_script usage optional
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 <hjensas@redhat.com>
1 parent 8eca676 commit 8bd3f89

File tree

5 files changed

+121
-50
lines changed

5 files changed

+121
-50
lines changed

roles/nat64_appliance/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ cifmw_nat64_appliance_download_timeout: 600 # 10 minutes
4747

4848
cifmw_nat64_ipv6_prefix: "2620:cf:cf:fc00::/64"
4949
cifmw_nat64_ipv6_tayga_address: "2620:cf:cf:fc00::3"
50+
51+
# Set to false to use standard ansible.builtin.shell instead of cifmw.general.ci_script
52+
# This makes the role usable outside of ci-framework context
53+
cifmw_nat64_appliance_use_ci_script: true
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Install required RPM packages
18+
tags:
19+
- packages
20+
become: true
21+
ansible.builtin.package:
22+
name:
23+
- python3-pip
24+
- qemu-img
25+
- dosfstools
26+
- xfsprogs
27+
state: present
28+
29+
- name: Install diskimage-builder in virtualenv
30+
tags:
31+
- packages
32+
ansible.builtin.pip:
33+
virtualenv_command: "python3 -m venv"
34+
virtualenv: "{{ cifmw_nat64_appliance_venv_dir }}"
35+
name:
36+
- diskimage-builder
37+
- setuptools
38+
39+
- name: Copy files to cifmw_nat64_appliance_dir
40+
ansible.builtin.copy:
41+
src: "{{ item }}"
42+
dest: "{{ cifmw_nat64_appliance_workdir }}/{{ item }}"
43+
mode: preserve
44+
loop:
45+
- "elements/"
46+
- nat64-appliance.yaml
47+
48+
- name: Clone edpm-image-builder (reset-bls-entries dib element)
49+
ansible.builtin.git:
50+
repo: https://github.com/openstack-k8s-operators/edpm-image-builder.git
51+
dest: "{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder"
52+
version: main
53+
54+
- name: Build the nat64-appliance image using DIB (with ci_script)
55+
when: cifmw_nat64_appliance_use_ci_script | bool
56+
ansible.builtin.include_tasks: build_with_ci_script.yml
57+
58+
- name: Build the nat64-appliance image using DIB (with shell)
59+
when: not (cifmw_nat64_appliance_use_ci_script | bool)
60+
ansible.builtin.include_tasks: build_with_shell.yml
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Build the nat64-appliance image using DIB (with ci_script)
18+
become: "{{ cifmw_nat64_appliance_run_dib_as_root | default(false) | bool }}"
19+
environment:
20+
ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements:{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder/dib/"
21+
DIB_IMAGE_CACHE: "{{ cifmw_nat64_appliance_workdir }}/cache"
22+
DIB_DEBUG_TRACE: '1'
23+
cifmw.general.ci_script:
24+
chdir: "{{ cifmw_nat64_appliance_workdir }}"
25+
output_dir: "{{ cifmw_nat64_appliance_basedir }}/artifacts"
26+
creates: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2"
27+
script: "{{ cifmw_nat64_appliance_venv_dir }}/bin/diskimage-builder nat64-appliance.yaml {{ extra_args | default('') }}"
28+
executable: "/bin/bash"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Build the nat64-appliance image using DIB (with shell)
18+
become: "{{ cifmw_nat64_appliance_run_dib_as_root | default(false) | bool }}"
19+
environment:
20+
ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements:{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder/dib/"
21+
DIB_IMAGE_CACHE: "{{ cifmw_nat64_appliance_workdir }}/cache"
22+
DIB_DEBUG_TRACE: '1'
23+
ansible.builtin.shell: |
24+
{{ cifmw_nat64_appliance_venv_dir }}/bin/diskimage-builder nat64-appliance.yaml {{ extra_args | default('') }}
25+
args:
26+
chdir: "{{ cifmw_nat64_appliance_workdir }}"
27+
creates: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2"
28+
executable: /bin/bash

roles/nat64_appliance/tasks/main.yml

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,56 +32,7 @@
3232
- name: Build NAT64 appliance image from source
3333
when:
3434
- cifmw_nat64_appliance_image_url | length == 0
35-
block:
36-
- name: Install required RPM packages
37-
tags:
38-
- packages
39-
become: true
40-
ansible.builtin.package:
41-
name:
42-
- python3-pip
43-
- qemu-img
44-
- dosfstools
45-
- xfsprogs
46-
state: present
47-
48-
- name: Install diskimage-builder in virtualenv
49-
tags:
50-
- packages
51-
ansible.builtin.pip:
52-
virtualenv_command: "python3 -m venv"
53-
virtualenv: "{{ cifmw_nat64_appliance_venv_dir }}"
54-
name:
55-
- diskimage-builder
56-
- setuptools
57-
58-
- name: Copy files to cifmw_nat64_appliance_dir
59-
ansible.builtin.copy:
60-
src: "{{ item }}"
61-
dest: "{{ cifmw_nat64_appliance_workdir }}/{{ item }}"
62-
mode: preserve
63-
loop:
64-
- "elements/"
65-
- nat64-appliance.yaml
66-
67-
- name: Clone edpm-image-builder (reset-bls-entries dib element)
68-
ansible.builtin.git:
69-
repo: https://github.com/openstack-k8s-operators/edpm-image-builder.git
70-
dest: "{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder"
71-
version: main
72-
73-
- name: Build the nat64-appliance image using DIB
74-
become: "{{ cifmw_nat64_appliance_run_dib_as_root | default(false) | bool }}"
75-
environment:
76-
ELEMENTS_PATH: "{{ cifmw_nat64_appliance_workdir }}/elements:{{ cifmw_nat64_appliance_workdir }}/edpm-image-builder/dib/"
77-
DIB_IMAGE_CACHE: "{{ cifmw_nat64_appliance_workdir }}/cache"
78-
DIB_DEBUG_TRACE: '1'
79-
cifmw.general.ci_script:
80-
chdir: "{{ cifmw_nat64_appliance_workdir }}"
81-
output_dir: "{{ cifmw_nat64_appliance_basedir }}/artifacts"
82-
creates: "{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2"
83-
script: "{{ cifmw_nat64_appliance_venv_dir }}/bin/diskimage-builder nat64-appliance.yaml {{ extra_args | default('') }}"
84-
executable: "/bin/bash"
35+
ansible.builtin.include_tasks: build_image.yml
8536

8637
- name: Download pre-built NAT64 appliance image
8738
when:

0 commit comments

Comments
 (0)