Add variable to "forcefully" enable/disable deb822 format

This commit is contained in:
LaggingHero 2025-02-11 19:08:52 +01:00
parent 23bc342d6d
commit de0ec22581
2 changed files with 19 additions and 6 deletions

View File

@ -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_deb822_format` variable. For example, if the one-line format is preferred, set the variable as follows:
```yaml
docker_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
```

View File

@ -1,8 +1,11 @@
---
- name: Check if the distribution is Ubuntu 24.04 or later and save it as a fact
ansible.builtin.set_fact:
- name: Check if deb822 format should be used and save it as a fact
vars:
is_ubuntu2404_or_greater: >-
{{ ansible_distribution == "Ubuntu" and ansible_distribution_version is version('24.04', '>=') }}
ansible.builtin.set_fact:
docker_use_deb822_format: >-
{{ docker_deb822_format | default(is_ubuntu2404_or_greater) }}
- name: Ensure apt key is not present in trusted.gpg.d
ansible.builtin.file:
@ -13,7 +16,7 @@
vars:
old_apt_source_list_files:
- /etc/apt/sources.list.d/download_docker_com_linux_{{ docker_apt_ansible_distribution }}.list
- "{{ is_ubuntu2404_or_greater | ansible.builtin.ternary('/etc/apt/sources.list.d/docker.list', '') }}"
- "{{ docker_use_deb822_format | ansible.builtin.ternary('/etc/apt/sources.list.d/docker.list', '') }}"
ansible.builtin.file:
path: "{{ item }}"
state: absent
@ -38,7 +41,7 @@
dependencies:
- apt-transport-https
- ca-certificates
- "{{ is_ubuntu2404_or_greater | ansible.builtin.ternary('python3-debian', '') }}"
- "{{ docker_use_deb822_format | ansible.builtin.ternary('python3-debian', '') }}"
apt:
name: "{{ dependencies | select }}"
state: present
@ -78,12 +81,12 @@
update_cache: true
when:
- docker_add_repo | bool
- ansible_distribution != "Ubuntu" or (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('24.04', '<'))
- not docker_use_deb822_format
- name: Manage the deb822 format
when:
- docker_add_repo | bool
- is_ubuntu2404_or_greater
- docker_use_deb822_format
block:
- name: Add Docker repository with deb822 format.
ansible.builtin.deb822_repository: