Compare commits

...

12 Commits

Author SHA1 Message Date
Jeff Geerling
b941efcdc4
Merge pull request #511 from sebdanielsson/deb822_repository
Refactor Debian setup to use deb822_repository
2025-08-19 00:44:34 -04:00
Sebastian
6343bc9148
Only one task for deleting the old repo is needed. Remove dependencies that are no longer needed for this role. 2025-08-18 20:56:23 +02:00
Sebastian
894e30654f
Keyring removal is already handled by deb822 module. 2025-08-18 20:45:45 +02:00
Sebastian
8818e2b3e3
Make sure that handlers run before package install 2025-07-21 14:54:41 +02:00
Sebastian
a44d1bee2a
Refactor Debian setup to use deb822_repository
- Replaces deprecated apt_repository and manual GPG key management with ansible.builtin.deb822_repository, introduced in apt 1.1.
- Updates handlers to use FQCNs.
2025-07-21 14:36:38 +02:00
Jeff Geerling
94b787389d
Merge pull request #504 from geerlingguy/revert-498-patch-1
Revert "Ensure the Docker daemon options file (`/etc/docker/daemon.json`) is deleted when no longer needed"
2025-04-05 07:42:05 -07:00
Jeff Geerling
24dee13f70
Revert "Ensure the Docker daemon options file (/etc/docker/daemon.json) is deleted when no longer needed" 2025-04-05 07:41:55 -07:00
Jeff Geerling
c8df987a56
Merge pull request #498 from spantaleev/patch-1
Ensure the Docker daemon options file (`/etc/docker/daemon.json`) is deleted when no longer needed
2025-04-05 07:41:35 -07:00
Jeff Geerling
d95b3fdc47
Merge pull request #497 from AliMehraji/master
update: docker_yum_gpg_key variable to get the distro gpg key
2025-04-05 07:40:36 -07:00
Ali Mehraji
1000ee6000
Merge branch 'geerlingguy:master' into master 2025-03-24 15:14:54 +03:30
Slavi Pantaleev
5a2fd928ad
Ensure the Docker daemon options file (/etc/docker/daemon.json) is deleted when no longer needed
If people set options in `docker_daemon_options` (e.g. `{'ipv6': false}`), the role will create the `/etc/docker/daemon.json` file and populate it with the options.

Later on, if people stop setting *all of these* options, the file used to remain in place (containing the old options) and cause trouble. This is unexpected.

If the Docker installation is managed by this role and the `/etc/docker/daemon.json` file is managed by it, it should also take care to:

- either delete the file when it's no longer necessary
- or populate it with empty options if that is what `docker_daemon_options` contains

Deleting the file instead of putting `{}` in it seems like the cleaner approach.

There's a chance that people would like to manage options in `/etc/docker/daemon.json` by themselves (without Ansible) and this new behavior when `docker_daemon_options` is empty, but this runs against having a managed Docker installation via Ansible.

This patch only deletes the `/etc/docker/daemon.json` file.

We could possibly delete the `/etc/docker` directory too, but it's more tricky to delete it only when it's empty. In some cases, the directory may contain other files and invoking the `file` module with `state: absent` will delete everything recursively, which is undesirable.
2025-03-09 16:20:51 +02:00
Ali Mehraji
6f0503c0fb update: docker_yum_gpg_key variable to get the distro specific yum gpg key 2025-02-19 12:54:53 +03:30
4 changed files with 29 additions and 48 deletions

View File

@ -106,7 +106,7 @@ Usually in combination with changing `docker_apt_repository` as well. `docker_ap
docker_yum_repo_url: "{{ docker_repo_url }}/{{ (ansible_distribution == 'Fedora') | ternary('fedora','centos') }}/docker-{{ docker_edition }}.repo"
docker_yum_repo_enable_nightly: '0'
docker_yum_repo_enable_test: '0'
docker_yum_gpg_key: "{{ docker_repo_url }}/centos/gpg"
docker_yum_gpg_key: "{{ docker_repo_url }}/{{ (ansible_distribution == 'Fedora') | ternary('fedora', 'centos') }}/gpg"
```
(Used only for RedHat/CentOS.) You can enable the Nightly or Test repo by setting the respective vars to `1`.

View File

@ -59,7 +59,7 @@ docker_apt_filename: "docker"
docker_yum_repo_url: "{{ docker_repo_url }}/{{ (ansible_distribution == 'Fedora') | ternary('fedora','centos') }}/docker-{{ docker_edition }}.repo"
docker_yum_repo_enable_nightly: '0'
docker_yum_repo_enable_test: '0'
docker_yum_gpg_key: "{{ docker_repo_url }}/centos/gpg"
docker_yum_gpg_key: "{{ docker_repo_url }}/{{ (ansible_distribution == 'Fedora') | ternary('fedora', 'centos') }}/gpg"
# A list of users who will be added to the docker group.
docker_users: []

View File

@ -1,7 +1,11 @@
---
- name: restart docker
service:
ansible.builtin.service:
name: docker
state: "{{ docker_restart_handler_state }}"
ignore_errors: "{{ ansible_check_mode }}"
when: docker_service_manage | bool
- name: apt update
ansible.builtin.apt:
update_cache: true

View File

@ -9,58 +9,35 @@
path: "/etc/apt/sources.list.d/download_docker_com_linux_{{ docker_apt_ansible_distribution | lower }}.list"
state: absent
- 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 }}"
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
name: Ensure old versions of Docker are not installed.
package:
# See https://docs.docker.com/engine/install/debian/#uninstall-old-versions
- name: Ensure old versions of Docker are not installed.
ansible.builtin.package:
name: "{{ docker_obsolete_packages }}"
state: absent
- name: Ensure legacy repo file is not present.
ansible.builtin.file:
path: "/etc/apt/sources.list.d/docker.list"
state: absent
- name: Ensure dependencies are installed.
apt:
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- python3-debian
state: present
when: docker_add_repo | bool
- name: Ensure directory exists for /etc/apt/keyrings
file:
path: /etc/apt/keyrings
state: directory
mode: "0755"
- name: Add or remove Docker repository.
ansible.builtin.deb822_repository:
name: docker
types: deb
uris: "{{ docker_repo_url }}/{{ ansible_distribution | lower }}"
suites: "{{ ansible_distribution_release }}"
components: "{{ docker_apt_release_channel }}"
signed_by: "{{ docker_apt_gpg_key }}"
state: "{{ 'present' if docker_add_repo | bool else 'absent' }}"
notify: apt update
- name: Add Docker apt key.
ansible.builtin.get_url:
url: "{{ docker_apt_gpg_key }}"
dest: /etc/apt/keyrings/docker.asc
mode: "0644"
force: false
checksum: "{{ docker_apt_gpg_key_checksum | default(omit) }}"
register: add_repository_key
ignore_errors: "{{ docker_apt_ignore_key_error }}"
when: docker_add_repo | bool
- name: Ensure curl is present (on older systems without SNI).
package: name=curl state=present
when: add_repository_key is failed and docker_add_repo | bool
- name: Add Docker apt key (alternative for older systems without SNI).
shell: >
curl -sSL {{ docker_apt_gpg_key }} | apt-key add -
when: add_repository_key is failed and docker_add_repo | bool
- name: Add Docker repository.
apt_repository:
repo: "{{ docker_apt_repository }}"
state: present
filename: "{{ docker_apt_filename }}"
update_cache: true
when: docker_add_repo | bool
- name: Ensure handlers are notified immediately to update the apt cache.
ansible.builtin.meta: flush_handlers