Skip to content

Commit

Permalink
Fix molecule broken envvar refs (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Jan 9, 2024
1 parent c1400a3 commit 494a3bf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions molecule/hold/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +24,5 @@ provisioner:
docker_packages:
- docker-ce
- docker-ce-cli
- containerd.io
verifier:
name: ansible
30 changes: 19 additions & 11 deletions molecule/hold/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions molecule/install/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tasks/repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 494a3bf

Please sign in to comment.