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 7b5033a..59a6a17 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -120,3 +120,13 @@ - include_tasks: docker-users.yml when: at_least_one_user_to_modify is defined +- name: Add Docker apt repo + ansible.builtin.apt_repository: + repo: >- + deb [arch={{ ansible_facts.architecture }}] + {{ docker_repo_url }}/{{ docker_apt_ansible_distribution | lower }} + {{ ansible_facts['lsb']['codename'] | default(ansible_facts.get('distribution_release', '')) }} + {{ docker_apt_release_channel }} + filename: "{{ docker_apt_filename }}" + state: present + when: docker_add_repo | bool and ansible_facts.os_family == 'Debian' diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml index ba2e17e..3955b86 100644 --- a/tasks/setup-Debian.yml +++ b/tasks/setup-Debian.yml @@ -16,9 +16,23 @@ state: absent - name: Ensure legacy repo file is not present. - ansible.builtin.file: - path: "/etc/apt/sources.list.d/docker.list" - state: absent + block: + - name: Check for legacy docker.list + ansible.builtin.stat: + path: "/etc/apt/sources.list.d/docker.list" + register: legacy_docker_list + - name: Check whether legacy docker.list references the official Docker repo + ansible.builtin.command: + cmd: grep -q "{{ docker_repo_url }}" /etc/apt/sources.list.d/docker.list + register: legacy_grep + ignore_errors: true + changed_when: false + + - name: Remove legacy docker.list if it does not reference the official Docker repo + ansible.builtin.file: + path: "/etc/apt/sources.list.d/docker.list" + state: absent + when: legacy_docker_list.stat.exists and legacy_grep.rc != 0 - name: Ensure dependencies are installed. ansible.builtin.apt: