From c77727b12239ec9937eccf04d6f3bfe1eafed3cb Mon Sep 17 00:00:00 2001 From: Nk-dir Date: Wed, 8 Oct 2025 18:07:41 +0000 Subject: [PATCH] molecule: add prepare playbook and bootstrap packages; guard apt repo for non-Debian --- molecule/default/molecule.yml | 1 + molecule/default/prepare.yml | 34 ++++++++++++++++++++++++++++++++++ tasks/main.yml | 4 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 molecule/default/prepare.yml diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 3c2f1e5..d209852 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -18,4 +18,5 @@ platforms: provisioner: name: ansible playbooks: + prepare: ${MOLECULE_PREPARE_PLAYBOOK:-prepare.yml} converge: ${MOLECULE_PLAYBOOK:-converge.yml} diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..5119a92 --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,34 @@ +--- +- name: Prepare + hosts: all + gather_facts: true + tasks: + - name: Install python3-apt for Debian/Ubuntu + apt: + name: python3-apt + state: present + update_cache: yes + when: ansible_facts.os_family == 'Debian' + + - name: Install common packages for RedHat family (best-effort) + block: + - name: Try to install python3-dnf + package: + name: python3-dnf + state: present + + - name: Try to install python3-libselinux + package: + name: python3-libselinux + state: present + when: ansible_facts.os_family == 'RedHat' + ignore_errors: true + + - name: Install packages for Suse family (best-effort) + block: + - name: Try to install python3-zypp + package: + name: python3-zypp + state: present + when: ansible_facts.os_family == 'Suse' + ignore_errors: true diff --git a/tasks/main.yml b/tasks/main.yml index 825ed95..feceeca 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -104,7 +104,7 @@ repo: >- deb [arch={{ ansible_facts.architecture }}] {{ docker_repo_url }}/{{ ansible_facts['distribution'] | lower }} - {{ ansible_facts['lsb']['codename'] }} {{ docker_apt_release_channel }} + {{ ansible_facts['lsb']['codename'] | default(ansible_facts.get('distribution_release', '')) }} filename: "{{ docker_apt_filename }}" state: present - when: docker_add_repo | bool + when: docker_add_repo | bool and ansible_facts.os_family == 'Debian'