Files
Kamino/roles/docker/molecule/default/verify.yml
T
Defame1297andClaude Sonnet 5.5 aad59fc339
Build / build (pull_request) Failing after 22s
Lint / lint (pull_request) Successful in 15s
Molecule / molecule (pull_request) Successful in 2m18s
feat(docker): add the docker role (#522)
Extracted from the environment repository, wave 1. Scrubbed of private
references: namespace mortis, no repository paths or issue numbers in
comments and docs, the removed docker_ufw_rules guard dropped, the molecule
scenario uses the FQCN and no provisioner environment overrides.
ansible-lint mocks the role's FQCN because CI checks the Collection out
outside an ansible_collections path.

Verified: the commit hooks. Not verified: the molecule scenario (CI only).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-11-08 18:59:26 +00:00

135 lines
4.9 KiB
YAML

---
# What the role is for, as far as stand-in packages can show it: the repository key and the
# source line are in place and apt really used them, the packages are installed from that
# repository, the unit is enabled and running, and the user joined the group. The second play
# runs the removal, which would break the checks of the first, so it comes last.
- name: Verify the install
hosts: all
vars:
docker_verify_packages: [docker-ce, docker-ce-cli, containerd.io]
tasks:
- name: Read the source list and the two keys
ansible.builtin.slurp:
src: "{{ item }}"
loop:
- /etc/apt/sources.list.d/docker.list
- /etc/apt/keyrings/docker.asc
- /srv/docker-stub-repo/docker.asc
register: docker_verify_files
- name: The source line carries the arch, the keyring and the release
ansible.builtin.assert:
that:
- >-
(docker_verify_files.results[0].content | b64decode) ==
'deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] file:///srv/docker-stub-repo '
~ ansible_facts['distribution_release'] ~ ' stable\n'
quiet: true
- name: The keyring is the key the repository published
ansible.builtin.assert:
that:
- docker_verify_files.results[1].content == docker_verify_files.results[2].content
quiet: true
- name: Stat the keyring
ansible.builtin.stat:
path: /etc/apt/keyrings/docker.asc
register: docker_verify_keyring
- name: The keyring is world-readable, as apt needs
ansible.builtin.assert:
that: docker_verify_keyring.stat.mode == "0644"
quiet: true
- name: Ask apt where docker-ce comes from
ansible.builtin.command: apt-cache policy docker-ce
register: docker_verify_policy
changed_when: false
- name: Apt installed docker-ce from the signed stand-in repository
ansible.builtin.assert:
that:
- "'Installed: 0.0.1~molecule' in docker_verify_policy.stdout"
- "'file:/srv/docker-stub-repo' in docker_verify_policy.stdout"
quiet: true
- name: Ask dpkg for the package states
ansible.builtin.command:
argv: [dpkg-query, --show, --showformat, "${db:Status-Status}\\n", "{{ item }}"]
loop: "{{ docker_verify_packages }}"
register: docker_verify_dpkg
changed_when: false
- name: Every package is installed
ansible.builtin.assert:
that: docker_verify_dpkg.results | map(attribute='stdout') | map('trim') | unique | list == ['installed']
quiet: true
- name: Ask systemd about the unit
ansible.builtin.systemd:
name: docker.service
register: docker_verify_unit
check_mode: true
- name: The unit is enabled and running
ansible.builtin.assert:
that:
- docker_verify_unit.status.UnitFileState == "enabled"
- docker_verify_unit.status.ActiveState == "active"
quiet: true
- name: Ask which groups the user is in
ansible.builtin.command: id -nG moleculeuser
register: docker_verify_groups
changed_when: false
- name: The user joined the docker group
ansible.builtin.assert:
that: "'docker' in docker_verify_groups.stdout.split()"
quiet: true
# docker_remove_data is set, so this also covers the destructive path: the packages are
# purged and /var/lib/docker, seeded in prepare.yml, is deleted. The removal stops the unit
# before the package takes it away, so it can only run once; a second run would fail on the
# missing unit, which is why it is not in the converge.
- name: Verify the removal
hosts: all
gather_facts: false
vars:
docker_remove: true
docker_remove_data: true
docker_verify_packages: [docker-ce, docker-ce-cli, containerd.io]
tasks:
- name: Remove Docker with its data
ansible.builtin.include_role:
name: mortis.kamino.docker
- name: Stat what the removal must delete
ansible.builtin.stat:
path: "{{ item }}"
loop:
- /etc/apt/sources.list.d/docker.list
- /etc/apt/keyrings/docker.asc
- /var/lib/docker
- /usr/lib/systemd/system/docker.service
register: docker_verify_gone
- name: The source list, the keyring, the data and the unit are gone
ansible.builtin.assert:
that: docker_verify_gone.results | map(attribute='stat.exists') | unique | list == [false]
quiet: true
- name: Ask dpkg for the package states
ansible.builtin.command:
argv: [dpkg-query, --show, --showformat, "${db:Status-Status}\\n", "{{ item }}"]
loop: "{{ docker_verify_packages }}"
register: docker_verify_dpkg
changed_when: false
failed_when: false
- name: No package is installed any more
ansible.builtin.assert:
that: "'installed' not in docker_verify_dpkg.results | map(attribute='stdout') | map('trim') | list"
quiet: true