Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deb822 format for repository source file #495

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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.

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
docker_repo_url: https://download.docker.com/linux
```
Expand Down
4 changes: 4 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
state: "{{ docker_restart_handler_state }}"
ignore_errors: "{{ ansible_check_mode }}"
when: docker_service_manage | bool

- name: Update apt cache
ansible.builtin.apt:
update_cache: true
47 changes: 42 additions & 5 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
---
- 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
ansible.builtin.file:
path: /etc/apt/trusted.gpg.d/docker.asc
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:
path: "/etc/apt/sources.list.d/download_docker_com_linux_{{ docker_apt_ansible_distribution }}.list"
path: "{{ item }}"
state: absent
loop: "{{ old_apt_source_list_files | select }}"

- name: Ensure the repo referencing the previous trusted.gpg.d key is not present
apt_repository:
repo: "deb [arch={{ docker_apt_arch }} signed-by=/etc/apt/trusted.gpg.d/docker.asc] {{ docker_repo_url }}/{{ docker_apt_ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"

Check warning on line 27 in tasks/setup-Debian.yml

View workflow job for this annotation

GitHub Actions / Lint

27:201 [line-length] line too long (224 > 200 characters)
state: absent
filename: "{{ docker_apt_filename }}"
update_cache: true
when: docker_add_repo | bool

- # See https://docs.docker.com/engine/install/debian/#uninstall-old-versions

Check warning on line 33 in tasks/setup-Debian.yml

View workflow job for this annotation

GitHub Actions / Lint

33:3 [comments] too few spaces before comment
name: Ensure old versions of Docker are not installed.
package:
name: "{{ docker_obsolete_packages }}"
state: absent

- name: Ensure dependencies are installed.
apt:
name:
vars:
dependencies:
- apt-transport-https
- ca-certificates
- "{{ docker_use_deb822_format | ansible.builtin.ternary('python3-debian', '') }}"
apt:
name: "{{ dependencies | select }}"
state: present
when: docker_add_repo | bool

Expand Down Expand Up @@ -63,4 +79,25 @@
state: present
filename: "{{ docker_apt_filename }}"
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