molecule: add prepare playbook and bootstrap packages; guard apt repo for non-Debian

This commit is contained in:
Nk-dir 2025-10-08 18:07:41 +00:00
parent 2ba74deefe
commit c77727b122
3 changed files with 37 additions and 2 deletions

View File

@ -18,4 +18,5 @@ platforms:
provisioner:
name: ansible
playbooks:
prepare: ${MOLECULE_PREPARE_PLAYBOOK:-prepare.yml}
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

View File

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

View File

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