From 780f8af1a4c1b8c5b0de30412cb8dcdaa809af27 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Wed, 26 Feb 2025 17:08:50 +0000 Subject: [PATCH] ci: Factor out image prep bootstrap as a role Promoting the script to a full template will fix some whitespace errors later. --- tests/image_prep/_container_setup.yml | 14 ++------------ tests/image_prep/roles/bootstrap/defaults/main.yml | 1 + tests/image_prep/roles/bootstrap/tasks/main.yml | 3 +++ .../roles/bootstrap/templates/bootstrap.sh.j2 | 13 +++++++++++++ 4 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 tests/image_prep/roles/bootstrap/defaults/main.yml create mode 100644 tests/image_prep/roles/bootstrap/tasks/main.yml create mode 100644 tests/image_prep/roles/bootstrap/templates/bootstrap.sh.j2 diff --git a/tests/image_prep/_container_setup.yml b/tests/image_prep/_container_setup.yml index 55e21efa..d894cd25 100644 --- a/tests/image_prep/_container_setup.yml +++ b/tests/image_prep/_container_setup.yml @@ -2,18 +2,8 @@ hosts: all strategy: linear gather_facts: false - tasks: - - name: Install bootstrap packages - raw: | - set -o errexit - set -o nounset - if type -p yum; then - yum -y install {{ bootstrap_packages | join(' ') }} - else - apt-get -y update - apt-get -y --no-install-recommends install {{ bootstrap_packages | join(' ') }} - fi - when: bootstrap_packages | length + roles: + - role: bootstrap - name: Setup containers hosts: all diff --git a/tests/image_prep/roles/bootstrap/defaults/main.yml b/tests/image_prep/roles/bootstrap/defaults/main.yml new file mode 100644 index 00000000..91e2fe57 --- /dev/null +++ b/tests/image_prep/roles/bootstrap/defaults/main.yml @@ -0,0 +1 @@ +bootstrap_packages: [] diff --git a/tests/image_prep/roles/bootstrap/tasks/main.yml b/tests/image_prep/roles/bootstrap/tasks/main.yml new file mode 100644 index 00000000..5ecaa49d --- /dev/null +++ b/tests/image_prep/roles/bootstrap/tasks/main.yml @@ -0,0 +1,3 @@ +- name: Bootstrap + raw: "{{ lookup('template', 'bootstrap.sh.j2') }}" + changed_when: true diff --git a/tests/image_prep/roles/bootstrap/templates/bootstrap.sh.j2 b/tests/image_prep/roles/bootstrap/templates/bootstrap.sh.j2 new file mode 100644 index 00000000..daffa178 --- /dev/null +++ b/tests/image_prep/roles/bootstrap/templates/bootstrap.sh.j2 @@ -0,0 +1,13 @@ +set -o errexit +set -o nounset + +{% if bootstrap_packages %} +if command -v apt-get; then + apt-get -y update + apt-get -y --no-install-recommends install {{ bootstrap_packages | join(' ') }} +elif command -v yum; then + yum -y install {{ bootstrap_packages | join(' ') }} +else + exit 42 +fi +{% endif %}