mirror of
https://github.com/geerlingguy/ansible-role-docker.git
synced 2025-07-23 13:48:32 +02:00
Merge d3e340b976
into acade8d01f
This commit is contained in:
commit
e877a3dae1
10
README.md
10
README.md
@ -82,6 +82,16 @@ docker_add_repo: true
|
|||||||
|
|
||||||
Controls whether this role will add the official Docker repository. Set to `false` if you want to use the default docker packages for your system or manage the package repository on your own.
|
Controls whether this role will add the official Docker repository. Set to `false` if you want to use the default docker packages for your system or manage the package repository on your own.
|
||||||
|
|
||||||
|
For any instance running Ubuntu 24.04 or later, the Docker repository source file will be in `deb822` format by default.
|
||||||
|
|
||||||
|
This behavior can be modified using the `docker_apt_deb822_format` variable. For example, if the one-line format is preferred, set the variable as follows:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
docker_apt_deb822_format: false
|
||||||
|
```
|
||||||
|
|
||||||
|
When set to `true`, the `deb822` format will be used for all Debian-based installations. Note that enabling this will also remove any existing `docker.list` file and install `python3-debian`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
docker_repo_url: https://download.docker.com/linux
|
docker_repo_url: https://download.docker.com/linux
|
||||||
```
|
```
|
||||||
|
@ -5,3 +5,7 @@
|
|||||||
state: "{{ docker_restart_handler_state }}"
|
state: "{{ docker_restart_handler_state }}"
|
||||||
ignore_errors: "{{ ansible_check_mode }}"
|
ignore_errors: "{{ ansible_check_mode }}"
|
||||||
when: docker_service_manage | bool
|
when: docker_service_manage | bool
|
||||||
|
|
||||||
|
- name: Update apt cache
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: true
|
||||||
|
@ -1,13 +1,26 @@
|
|||||||
---
|
---
|
||||||
|
- name: Check if deb822 format should be used and save it as a fact
|
||||||
|
vars:
|
||||||
|
is_ubuntu2304_or_greater: "{{ ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('23.04', '>=') }}"
|
||||||
|
is_debian12_or_greater: "{{ ansible_distribution == 'Debian' and ansible_distribution_version is version('12', '>=') }}"
|
||||||
|
is_deb822_preferred: "{{ is_ubuntu2304_or_greater or is_debian12_or_greater }}"
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
docker_use_deb822_format: "{{ docker_apt_deb822_format | default(is_deb822_preferred) }}"
|
||||||
|
|
||||||
- name: Ensure apt key is not present in trusted.gpg.d
|
- name: Ensure apt key is not present in trusted.gpg.d
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/apt/trusted.gpg.d/docker.asc
|
path: /etc/apt/trusted.gpg.d/docker.asc
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Ensure old apt source list is not present in /etc/apt/sources.list.d
|
- name: Ensure old apt source list files are not present in /etc/apt/sources.list.d
|
||||||
|
vars:
|
||||||
|
old_apt_source_list_files:
|
||||||
|
- /etc/apt/sources.list.d/download_docker_com_linux_{{ docker_apt_ansible_distribution }}.list
|
||||||
|
- "{{ docker_use_deb822_format | ansible.builtin.ternary('/etc/apt/sources.list.d/docker.list', '') }}"
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "/etc/apt/sources.list.d/download_docker_com_linux_{{ docker_apt_ansible_distribution }}.list"
|
path: "{{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
loop: "{{ old_apt_source_list_files | select }}"
|
||||||
|
|
||||||
- name: Ensure the repo referencing the previous trusted.gpg.d key is not present
|
- name: Ensure the repo referencing the previous trusted.gpg.d key is not present
|
||||||
apt_repository:
|
apt_repository:
|
||||||
@ -24,10 +37,13 @@
|
|||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Ensure dependencies are installed.
|
- name: Ensure dependencies are installed.
|
||||||
apt:
|
vars:
|
||||||
name:
|
dependencies:
|
||||||
- apt-transport-https
|
- apt-transport-https
|
||||||
- ca-certificates
|
- ca-certificates
|
||||||
|
- "{{ docker_use_deb822_format | ansible.builtin.ternary('python3-debian', '') }}"
|
||||||
|
apt:
|
||||||
|
name: "{{ dependencies | select }}"
|
||||||
state: present
|
state: present
|
||||||
when: docker_add_repo | bool
|
when: docker_add_repo | bool
|
||||||
|
|
||||||
@ -63,4 +79,25 @@
|
|||||||
state: present
|
state: present
|
||||||
filename: "{{ docker_apt_filename }}"
|
filename: "{{ docker_apt_filename }}"
|
||||||
update_cache: true
|
update_cache: true
|
||||||
when: docker_add_repo | bool
|
when:
|
||||||
|
- docker_add_repo | bool
|
||||||
|
- not docker_use_deb822_format
|
||||||
|
|
||||||
|
- name: Manage the deb822 format
|
||||||
|
when:
|
||||||
|
- docker_add_repo | bool
|
||||||
|
- docker_use_deb822_format
|
||||||
|
block:
|
||||||
|
- name: Add Docker repository with deb822 format.
|
||||||
|
ansible.builtin.deb822_repository:
|
||||||
|
name: "{{ docker_apt_filename }}"
|
||||||
|
types: deb
|
||||||
|
uris: "{{ docker_repo_url }}/{{ ansible_distribution | lower }}"
|
||||||
|
suites: "{{ ansible_distribution_release }}"
|
||||||
|
components: "{{ docker_apt_release_channel }}"
|
||||||
|
signed_by: /etc/apt/keyrings/docker.asc
|
||||||
|
architectures: "{{ docker_apt_arch }}"
|
||||||
|
notify: Update apt cache
|
||||||
|
|
||||||
|
- name: Ensure handlers are notified immediately to update the apt cache.
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
Loading…
Reference in New Issue
Block a user