diff --git a/doc/source/dib-roles.rst b/doc/source/dib-roles.rst new file mode 100644 index 000000000..7b7b72b4a --- /dev/null +++ b/doc/source/dib-roles.rst @@ -0,0 +1,4 @@ +Diskimage-Builder Roles +======================= + +.. zuul:autorole:: ensure-dib diff --git a/doc/source/roles.rst b/doc/source/roles.rst index 151d92d29..a2fab2a6a 100644 --- a/doc/source/roles.rst +++ b/doc/source/roles.rst @@ -14,6 +14,7 @@ Roles cloud-roles container-roles deprecated-roles + dib-roles galaxy-roles go-roles hashicorp-roles diff --git a/roles/ensure-dib/README.rst b/roles/ensure-dib/README.rst new file mode 100644 index 000000000..a8ad5c51e --- /dev/null +++ b/roles/ensure-dib/README.rst @@ -0,0 +1,28 @@ +This role installs diskimage-builder and dependencies. + +Currently, only Ubuntu and Debian distributions are supported. + +.. note:: + + The disk-image-create script will be located in + `{{ dib_venv_dir }}/bin/disk-image-create`. + +**Role variables** + +.. zuul:rolevar:: ensure_dib_venv_dir + :default: "{{ ansible_user_dir }}/dib" + + Directory for the virtualenv to install the diskimage-builder. + +.. zuul:rolevar:: ensure_dib_version + :default: undefined + + The version of diskimage-builder to install. The default is to install the + lastest version. + +**Output Variables** + +.. zuul:rolevar:: ensure_dib_command + + This variable points to the disk-image-create command installed in the + {{ dib_venv_dir }}. diff --git a/roles/ensure-dib/defaults/main.yaml b/roles/ensure-dib/defaults/main.yaml new file mode 100644 index 000000000..4f27b3371 --- /dev/null +++ b/roles/ensure-dib/defaults/main.yaml @@ -0,0 +1,2 @@ +ensure_dib_venv_dir: "{{ ansible_user_dir }}/dib" +ensure_dib_version: diff --git a/roles/ensure-dib/tasks/main.yaml b/roles/ensure-dib/tasks/main.yaml new file mode 100644 index 000000000..071f232d6 --- /dev/null +++ b/roles/ensure-dib/tasks/main.yaml @@ -0,0 +1,69 @@ +- name: Make sure the role is run on Debian or Ubuntu + fail: + msg: "This role supports Debian and Ubuntu distributions only" + when: ansible_distribution not in ["Debian", "Ubuntu"] + +- name: Install diskimage-builder requirements + become: true + package: + state: present + name: + # these deps are taken from the upstream + # openstack/diskimage-builder/bindep.txt + - apt-transport-https + - curl + - debootstrap + - dosfstools + - gdisk + - git + - gnupg2 + - inetutils-ping + - kpartx + - qemu-utils + - rpm + - squashfs-tools + - sudo + - uuid-runtime + - zstd + +- name: Check if diskimage-builder is installed + shell: > + command -v {{ ensure_dib_venv_dir }}/bin/disk-image-create + disk-image-create + args: + executable: /bin/bash + register: dib_preinstalled + ignore_errors: true + +- name: Export preinstalled dib executable + when: dib_preinstalled is successful + set_fact: + ensure_dib_command: "{{ dib_preinstalled.stdout_lines[0] }}" + cacheable: true + +- name: Install dib in venv + when: dib_preinstalled is not successful + block: + - name: Ensure pip + include_role: + name: ensure-pip + - name: Install latest diskimage-builder + when: not ensure_dib_version + pip: + name: + - setuptools + - diskimage-builder + virtualenv: "{{ ensure_dib_venv_dir }}" + virtualenv_command: "{{ ensure_pip_virtualenv_command }}" + - name: Install versioned diskimage-builder + when: ensure_dib_version + pip: + name: + - setuptools + - "diskimage-builder=={{ ensure_dib_version }}" + virtualenv: "{{ ensure_dib_venv_dir }}" + virtualenv_command: "{{ ensure_pip_virtualenv_command }}" + - name: Export DIB binary path + set_fact: + ensure_dib_command: "{{ ensure_dib_venv_dir }}/bin/disk-image-create" + cacheable: true diff --git a/test-playbooks/diskimage-builder/ensure-dib.yaml b/test-playbooks/diskimage-builder/ensure-dib.yaml new file mode 100644 index 000000000..635cb0e2d --- /dev/null +++ b/test-playbooks/diskimage-builder/ensure-dib.yaml @@ -0,0 +1,10 @@ +- hosts: all + roles: + - ensure-dib + tasks: + - name: Run build-disk-image + command: "{{ ensure_dib_command }} --help" + register: dib + - name: Assert dib being executed successfully + assert: + that: dib is successful diff --git a/zuul-tests.d/diskimage-builder-roles.yaml b/zuul-tests.d/diskimage-builder-roles.yaml new file mode 100644 index 000000000..f8329b3c6 --- /dev/null +++ b/zuul-tests.d/diskimage-builder-roles.yaml @@ -0,0 +1,71 @@ +- job: + name: zuul-jobs-test-ensure-dib + description: Test the ensure-dib role + files: + - roles/ensure-dib/.* + - test-playbooks/diskimage-builder/.* + run: test-playbooks/diskimage-builder/ensure-dib.yaml + tags: debuntu-platforms + +- job: + name: zuul-jobs-test-ensure-dib-debian-bookworm + description: Test the ensure-dib role on debian-bookworm + parent: zuul-jobs-test-ensure-dib + tags: auto-generated + nodeset: + nodes: + - name: debian-bookworm + label: debian-bookworm + +- job: + name: zuul-jobs-test-ensure-dib-debian-bullseye + description: Test the ensure-dib role on debian-bullseye + parent: zuul-jobs-test-ensure-dib + tags: auto-generated + nodeset: + nodes: + - name: debian-bullseye + label: debian-bullseye + +- job: + name: zuul-jobs-test-ensure-dib-ubuntu-focal + description: Test the ensure-dib role on ubuntu-focal + parent: zuul-jobs-test-ensure-dib + tags: auto-generated + nodeset: + nodes: + - name: ubuntu-focal + label: ubuntu-focal + +- job: + name: zuul-jobs-test-ensure-dib-ubuntu-jammy + description: Test the ensure-dib role on ubuntu-jammy + parent: zuul-jobs-test-ensure-dib + tags: auto-generated + nodeset: + nodes: + - name: ubuntu-jammy + label: ubuntu-jammy + +- job: + name: zuul-jobs-test-ensure-dib-ubuntu-noble + description: Test the ensure-dib role on ubuntu-noble + parent: zuul-jobs-test-ensure-dib + tags: auto-generated + nodeset: + nodes: + - name: ubuntu-noble + label: ubuntu-noble + +- project: + check: + jobs: &id001 + - zuul-jobs-test-ensure-dib-debian-bookworm + - zuul-jobs-test-ensure-dib-debian-bullseye + - zuul-jobs-test-ensure-dib-ubuntu-focal + - zuul-jobs-test-ensure-dib-ubuntu-jammy + - zuul-jobs-test-ensure-dib-ubuntu-noble + gate: + jobs: *id001 + periodic-weekly: + jobs: *id001