From 494a3bf64e6d9cc3d565d4b0041880425de68975 Mon Sep 17 00:00:00 2001 From: Teodoro Cook Date: Tue, 9 Jan 2024 14:39:56 -0600 Subject: [PATCH] Fix molecule broken envvar refs (#28) --- Makefile | 4 +++- defaults/main.yml | 1 - molecule/hold/molecule.yml | 5 ++--- molecule/hold/verify.yml | 30 +++++++++++++++++++----------- molecule/install/molecule.yml | 4 ++-- tasks/repo.yml | 4 ++-- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 3636edf..a3de9af 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,9 @@ collections: requirements: roles collections dependency create prepare converge idempotence side-effect verify destroy login reset: - MOLECULE_DOCKER_IMAGE=${MOLECULE_DOCKER_IMAGE} poetry run molecule $@ -s ${MOLECULE_SCENARIO} + MOLECULE_DOCKER_IMAGE=${MOLECULE_DOCKER_IMAGE} \ + MOLECULE_DOCKER_COMMAND=${MOLECULE_DOCKER_COMMAND} \ + poetry run molecule $@ -s ${MOLECULE_SCENARIO} ignore: poetry run ansible-lint --generate-ignore diff --git a/defaults/main.yml b/defaults/main.yml index c84e132..157abd2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,7 +12,6 @@ docker_repo_manage: "{{ docker_packages_state != 'absent' }}" docker_packages: - docker-ce - docker-ce-cli - - containerd.io docker_packages_state: present docker_configuration_template: mountflags.conf.j2 diff --git a/molecule/hold/molecule.yml b/molecule/hold/molecule.yml index 0ce2983..bfded11 100644 --- a/molecule/hold/molecule.yml +++ b/molecule/hold/molecule.yml @@ -5,9 +5,9 @@ driver: name: docker platforms: - name: docker-hold - image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible + image: geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible pre_build_image: true - command: ${MOLECULE_COMMAND:-"/lib/systemd/systemd"} + command: ${MOLECULE_DOCKER_COMMAND:-"/lib/systemd/systemd"} cgroupns_mode: host volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw @@ -24,6 +24,5 @@ provisioner: docker_packages: - docker-ce - docker-ce-cli - - containerd.io verifier: name: ansible diff --git a/molecule/hold/verify.yml b/molecule/hold/verify.yml index ba4b22e..838e419 100644 --- a/molecule/hold/verify.yml +++ b/molecule/hold/verify.yml @@ -63,27 +63,35 @@ ansible.builtin.package_facts: - name: Verify package versions - ansible.builtin.fail: - msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + ansible.builtin.assert: + that: + - _package in packages + - _version == _installed + fail_msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + success_msg: "Installed version for package {{ _package }} is {{ _installed }}" vars: _package: "{{ item.split('=') | first }}" _version: "{{ item.split('=') | last }}" _installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}" + loop_control: + label: "{{ _package }}" loop: "{{ docker_package_list }}" - when: - - ansible_os_family == "Debian" - - _package not in packages or _version != _installed + when: ansible_os_family == "Debian" - name: Verify package versions - ansible.builtin.fail: - msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + ansible.builtin.assert: + that: + - _package in packages + - _version == _installed + fail_msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + success_msg: "Installed version for package {{ _package }} is {{ _installed }}" vars: _prefix: "^{{ _package }}-" _suffix: "-.*$" _package: "{{ item.0 }}" - _version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') }}" + _version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') | split(':') | last }}" _installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}" + loop_control: + label: "{{ _package }}" loop: "{{ docker_packages | zip(docker_package_list) }}" - when: - - ansible_os_family == "RedHat" - - _package not in packages or _version != _installed + when: ansible_os_family == "RedHat" diff --git a/molecule/install/molecule.yml b/molecule/install/molecule.yml index 0954ed0..e22c57a 100644 --- a/molecule/install/molecule.yml +++ b/molecule/install/molecule.yml @@ -5,9 +5,9 @@ driver: name: docker platforms: - name: docker-install - image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible + image: geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible pre_build_image: true - command: ${MOLECULE_COMMAND:-"/lib/systemd/systemd"} + command: ${MOLECULE_DOCKER_COMMAND:-"/lib/systemd/systemd"} cgroupns_mode: host volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw diff --git a/tasks/repo.yml b/tasks/repo.yml index 62dc921..184df2a 100644 --- a/tasks/repo.yml +++ b/tasks/repo.yml @@ -64,8 +64,8 @@ - name: Remove yum repository ansible.builtin.file: dest: /etc/yum.repos.d/docker.repo - state: "{{ docker_repo_state }}" - mode: 0644 + state: absent + when: docker_repo_state == 'absent' - name: Flush handlers ansible.builtin.meta: flush_handlers