Add ensure-dib role

Role installs the diskimage-builder in a virtualenv.

Change-Id: I0801daa6d5b8039bfbdefb7357942b1c5a58732f
This commit is contained in:
Simon Westphahl 2024-06-27 09:11:36 +02:00 committed by Benjamin Schanzel
parent ec242bac78
commit e749223328
No known key found for this signature in database
7 changed files with 185 additions and 0 deletions

4
doc/source/dib-roles.rst Normal file
View File

@ -0,0 +1,4 @@
Diskimage-Builder Roles
=======================
.. zuul:autorole:: ensure-dib

View File

@ -14,6 +14,7 @@ Roles
cloud-roles cloud-roles
container-roles container-roles
deprecated-roles deprecated-roles
dib-roles
galaxy-roles galaxy-roles
go-roles go-roles
hashicorp-roles hashicorp-roles

View File

@ -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 }}.

View File

@ -0,0 +1,2 @@
ensure_dib_venv_dir: "{{ ansible_user_dir }}/dib"
ensure_dib_version:

View File

@ -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

View File

@ -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

View File

@ -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