Files
Kamino/roles/docker/README.md
T
Defame1297 234648919c
Build / build (pull_request) Successful in 27s
Molecule / molecule (pull_request) Successful in 4s
Lint / lint (pull_request) Successful in 1m21s
docs(roles): bring every role README to the fixed heading set
Every public role README has the headings Supported platforms, Requirements
and run order, Role variables, Entry points (when several), Variables set by
the role (when any), Tags, Example play, Tests and Notes, in that order, with
an "Idempotent" line in Notes. Role-specific sections move under Entry points
or Notes; nothing is removed. The internal _binary_update README keeps its own
headings and gains the platform and Idempotent lines.

Closes #136

Assisted-by: Claude Code:claude-opus-5-5
2026-11-25 17:24:27 +00:00

79 lines
6.0 KiB
Markdown

# docker
Installs Docker Engine from the upstream Docker APT repository, optionally updates it, or removes it, and adds listed users to the `docker` group. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The key and repository URLs point at `download.docker.com/linux/ubuntu`, and the source line uses `ansible_distribution_release`. The apt architecture is derived from the host (`x86_64` gives `amd64`, `aarch64` gives `arm64`); any other architecture fails the play until `docker_apt_arch` is set. A limited molecule scenario covers the role's own logic (see [Tests](#tests)); the real Docker Engine is not tested.
Untested platforms: Ubuntu releases other than 24.04; `meta/main.yml` declares Ubuntu `all`.
The role targets Ubuntu hosts only: it installs from Docker's Ubuntu repository, so it does not cover Debian trixie (Proxmox hosts).
## Requirements and run order
- Needs gathered facts and privilege escalation.
- Use it by its fully qualified name, `mortis.kamino.docker`.
- Run it before any role that needs the Docker group. Roles that install later and create their own user must add that user to the group themselves (see `docker_users`).
- Role dependencies: none.
- The `ufw` role is not a dependency and is not called: Docker publishes ports through iptables and owns no UFW rule.
## Role variables
| Variable | Default | Required | Description |
|---|---|---|---|
| `docker_remove` | `false` | no | Remove Docker instead of installing it. |
| `docker_remove_data` | `false` | no | With `docker_remove`, purge packages and delete `/var/lib/docker`. |
| `docker_update` | `false` | no | Upgrade packages to their current candidate version. |
| `docker_packages` | `docker-ce`, `docker-ce-cli`, `containerd.io` | no | Packages managed. |
| `docker_keyring_path` | `/etc/apt/keyrings/docker.asc` | no | Repository key location. |
| `docker_apt_list_path` | `/etc/apt/sources.list.d/docker.list` | no | APT source file. |
| `docker_gpg_url` | `https://download.docker.com/linux/ubuntu/gpg` | no | Key URL. |
| `docker_repo_base_url` | `https://download.docker.com/linux/ubuntu` | no | Repository base URL. |
| `docker_apt_arch` | derived from the host | no | Architecture in the APT source. Empty derives it (`x86_64` gives `amd64`, `aarch64` gives `arm64`); another architecture fails until this is set. A value set here is always used; lowercase letters and digits only. |
| `docker_service` | `docker` | no | systemd unit name. |
| `docker_group` | `docker` | no | Group for `docker_users`. |
| `docker_users` | `[]` | no | Users added to the group. |
## Tags
`docker` (everything), `install`, `update`, `remove`, `configure` (group membership). The tasks in `remove.yml` carry `docker` and `remove`.
Update (`docker_update: true`) and removal (`docker_remove: true`) are opt-in: run them on a host that is safe to change.
## Example play
```yaml
- hosts: standalone_vms
roles:
- role: mortis.kamino.docker
vars:
docker_users: [deploy]
```
## Tests
`molecule/default` runs in CI only (`.gitea/workflows/molecule.yml`, no local runner), on one platform: Ubuntu 24.04 (noble), the `molecule-ubuntu2404` test container (`${MOLECULE_IMAGE}`). A real Docker Engine cannot run there: `dockerd` needs the bridge, iptables rules and a delegated cgroup, and the container has no privileged mode. So the scenario builds a local APT repository, signs it with a throwaway key, and points the role at it with `docker_gpg_url` and `docker_repo_base_url`. The repository holds empty stand-ins for `docker-ce`, `docker-ce-cli` and `containerd.io`. The stand-in `docker-ce` ships a stub `docker.service` (`sleep infinity`) and creates the `docker` group, as the real package does.
What it shows, with the role's tasks running unchanged:
- The key is fetched, stored at `docker_keyring_path` with mode `0644`, and apt really verifies the repository against it (an unsigned or wrongly signed repository would leave no install candidate).
- The source line has the architecture, the `signed-by` keyring and `ansible_distribution_release`.
- The packages are installed from that repository, the unit is enabled and active, and `docker_users` join `docker_group`.
- `docker_remove` with `docker_remove_data` removes the source line, the keyring, the packages, the unit and `/var/lib/docker`.
- The argument check refuses a mapping for `docker_users` and a non-boolean `docker_remove`.
- A second run changes nothing (molecule's idempotence check).
What it does not show: that the upstream repository and key at `download.docker.com` are reachable and valid, that the real packages install, that `dockerd` starts, anything about container networking or iptables, the `docker_update` path (`tasks/update.yml`), and removal without `docker_remove_data` (the removal stops the unit first, so it can run only once per install). It needs the Ubuntu mirrors, for the `curl` the role installs. These gaps are a known residual risk of the role.
## Notes
- Idempotent: yes.
- `docker_remove` is checked first: when true, only `remove.yml` runs.
- Removal with `docker_remove_data` is destructive. It deletes `/var/lib/docker`.
- The update task resolves each package's candidate with `apt-cache policy` and fails if a package has none. It installs `package=version`, never `latest`.
- Installing or updating the packages notifies `Restart docker`. The `meta: flush_handlers` at the end of `tasks/main.yml` is untagged, so it runs only without a `--tags` selection; under `--tags update` (or `install`) it is skipped and the handler runs at the end of the play instead.
- Do not combine with anything that installs the distro `docker.io` package on the same host: this role installs `docker-ce` from Docker's repository, and the two packages conflict.
- Docker bypasses UFW for published ports (`-p`), so UFW rules do not restrict container ports.
- `no_log` is not used: the role handles no secrets.