docker_apt_arch defaults to empty, which derives amd64 or arm64 from the host architecture; another architecture fails the play, and a set value is always used. Assisted-by: Claude Code
136 lines
5.0 KiB
YAML
136 lines
5.0 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
|
|
|
|
# amd64 because the Molecule container is x86_64: the role derives the architecture from the host now.
|
|
- 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
|