Remove /etc/docker/daemon.json when no Docker options are set anymore

This commit is contained in:
Slavi Pantaleev 2025-03-09 16:03:15 +02:00
parent 5aa8bf9c3d
commit bd073bca74
3 changed files with 31 additions and 0 deletions

View File

@ -21,6 +21,8 @@ matrix_playbook_docker_installation_enabled: true
matrix_playbook_docker_installation_daemon_options: "{{ matrix_playbook_docker_installation_daemon_options_auto | combine(matrix_playbook_docker_installation_daemon_options_custom, recursive=True) }}" matrix_playbook_docker_installation_daemon_options: "{{ matrix_playbook_docker_installation_daemon_options_auto | combine(matrix_playbook_docker_installation_daemon_options_custom, recursive=True) }}"
matrix_playbook_docker_installation_daemon_options_file_path: /etc/docker/daemon.json
# Since Docker 27.0.1, Docker daemon options do not need to be changed to enable IPv6 support on the daemon side. # Since Docker 27.0.1, Docker daemon options do not need to be changed to enable IPv6 support on the daemon side.
# See: https://docs.docker.com/engine/release-notes/27/#ipv6 # See: https://docs.docker.com/engine/release-notes/27/#ipv6
# We only enable `ip6tables` and `experimental` for people who explicitly request it (perhaps due to running an old Docker version). # We only enable `ip6tables` and `experimental` for people who explicitly request it (perhaps due to running an old Docker version).

View File

@ -0,0 +1,20 @@
---
# ansible-role-docker creates the Docker daemon options file (`/etc/docker/daemon.json`) when options are set
# via `matrix_playbook_docker_installation_daemon_options` (which influences the `docker_daemon_options` variable of the role).
# See: https://github.com/geerlingguy/ansible-role-docker/blob/acade8d01f11bcd5efecba6d8211138d7567ce4b/tasks/main.yml#L53-L66
#
# However, it doesn't delete the file when the options list is empty.
#
# This means that people who previously force-disabled IPv6 (and injected `{'ipv6': false}` options, etc)
# or had some other custom options had that file created for them.
# Later, when they stopped setting these options, they were stuck with the configuration file that still retained them.
#
# Here, we make the file go away of no options are set.
# Idealy, this task would be part of the `ansible-role-docker` role, but it's not (yet).
- name: Ensure the Docker daemon options file is deleted when no longer needed
when: matrix_playbook_docker_installation_daemon_options.keys() | length == 0
ansible.builtin.file:
path: "{{ matrix_playbook_docker_installation_daemon_options_file_path }}"
state: absent
notify: restart docker

View File

@ -28,6 +28,15 @@
block: block:
- ansible.builtin.include_tasks: "{{ role_path }}/tasks/debian_docker_trusted_gpg_d_migration_migration.yml" - ansible.builtin.include_tasks: "{{ role_path }}/tasks/debian_docker_trusted_gpg_d_migration_migration.yml"
- when: matrix_playbook_docker_installation_enabled | bool
tags:
- setup-all
- install-all
- setup-docker
- install-docker
block:
- ansible.builtin.include_tasks: "{{ role_path }}/tasks/docker_daemon_options_file_cleanup.yml"
- tags: - tags:
- setup-all - setup-all
- install-all - install-all