The key that signs the Docker repository was trusted as whatever the URL served. It is now checked against a pinned sha256, so a changed key stops the install until a person has verified it. Assisted-by: Claude Code
62 lines
1.8 KiB
YAML
62 lines
1.8 KiB
YAML
---
|
|
- name: Install prerequisite packages
|
|
become: true
|
|
ansible.builtin.apt:
|
|
name:
|
|
- ca-certificates
|
|
- curl
|
|
state: present
|
|
update_cache: true
|
|
cache_valid_time: 3600
|
|
tags: [docker, install]
|
|
|
|
- name: Ensure APT keyrings directory exists
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: /etc/apt/keyrings
|
|
state: directory
|
|
mode: "0755"
|
|
tags: [docker, install]
|
|
|
|
- name: Install Docker APT GPG key
|
|
become: true
|
|
ansible.builtin.get_url:
|
|
url: "{{ docker_gpg_url }}"
|
|
dest: "{{ docker_keyring_path }}"
|
|
checksum: "sha256:{{ docker_keyring_checksum }}"
|
|
mode: "0644"
|
|
tags: [docker, install]
|
|
|
|
- name: Install Docker APT source list
|
|
become: true
|
|
ansible.builtin.copy:
|
|
dest: "{{ docker_apt_list_path }}"
|
|
content: |
|
|
deb [arch={{ __docker_apt_arch }} signed-by={{ docker_keyring_path }}] {{ docker_repo_base_url }} {{ ansible_facts['distribution_release'] }} stable
|
|
mode: "0644"
|
|
register: __docker_apt_source
|
|
tags: [docker, install]
|
|
|
|
- name: Install Docker Engine packages
|
|
become: true
|
|
ansible.builtin.apt:
|
|
name: "{{ docker_packages }}"
|
|
state: present
|
|
# Always refreshed: a run that wrote the source line but failed to fetch its lists heals here.
|
|
update_cache: true
|
|
register: __docker_packages
|
|
notify: Restart docker
|
|
# Under --check a new source line is only simulated, so apt would find no Docker package.
|
|
when: not ansible_check_mode or __docker_apt_source is not changed
|
|
tags: [docker, install]
|
|
|
|
- name: Enable and start Docker service
|
|
become: true
|
|
ansible.builtin.systemd:
|
|
name: "{{ docker_service }}"
|
|
enabled: true
|
|
state: started
|
|
# Under --check on a host without the packages there is no unit to start yet.
|
|
when: not ansible_check_mode or (__docker_apt_source is not changed and __docker_packages is not changed)
|
|
tags: [docker, install]
|