'No package matching docker-ce' happens when Docker has no repo for the VM's release codename (common on non-LTS Ubuntu). Add docker_apt_codename (defaults to the detected release; override to e.g. noble on non-LTS) and refresh the apt cache right after adding the repo so index errors surface immediately instead of as a missing package. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
68 lines
2 KiB
YAML
68 lines
2 KiB
YAML
---
|
|
- name: Create Docker apt keyring dir
|
|
ansible.builtin.file:
|
|
path: /etc/apt/keyrings
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Add Docker's official GPG key
|
|
ansible.builtin.get_url:
|
|
url: https://download.docker.com/linux/ubuntu/gpg
|
|
dest: /etc/apt/keyrings/docker.asc
|
|
mode: "0644"
|
|
|
|
- name: Add Docker apt repository
|
|
ansible.builtin.apt_repository:
|
|
repo: >-
|
|
deb [arch={{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}
|
|
signed-by=/etc/apt/keyrings/docker.asc]
|
|
https://download.docker.com/linux/ubuntu {{ docker_apt_codename }} stable
|
|
filename: docker
|
|
state: present
|
|
register: docker_repo
|
|
|
|
- name: Refresh apt cache after adding the Docker repo
|
|
ansible.builtin.apt:
|
|
update_cache: true
|
|
when: docker_repo is changed
|
|
|
|
- name: Ensure the ZFS docker dataset is mounted at the data-root
|
|
ansible.builtin.command: "zfs get -H -o value mounted {{ zfs_pool_name }}/platform/docker"
|
|
register: docker_ds_mounted
|
|
changed_when: false
|
|
failed_when: docker_ds_mounted.stdout != "yes"
|
|
# The zfs role creates tank/platform/docker with mountpoint=/var/lib/docker.
|
|
# This guards against installing Docker onto the wrong (non-ZFS) filesystem.
|
|
|
|
- name: Ensure /etc/docker exists
|
|
ansible.builtin.file:
|
|
path: /etc/docker
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: Write Docker daemon configuration (before first start, so the zfs
|
|
storage driver initializes on the empty ZFS data-root)
|
|
ansible.builtin.template:
|
|
src: daemon.json.j2
|
|
dest: /etc/docker/daemon.json
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
notify: Restart docker
|
|
|
|
- name: Install Docker Engine + Compose plugin
|
|
ansible.builtin.apt:
|
|
name:
|
|
- docker-ce
|
|
- docker-ce-cli
|
|
- containerd.io
|
|
- docker-buildx-plugin
|
|
- docker-compose-plugin
|
|
state: present
|
|
update_cache: true
|
|
|
|
- name: Ensure Docker is enabled and running
|
|
ansible.builtin.systemd:
|
|
name: docker
|
|
enabled: true
|
|
state: started
|