fix(system_docker): fix daemon.json corruption on re-run
Two bugs caused daemon.json to be overwritten with invalid content:
- Invalid `when` condition using unsupported Ansible inline stat syntax,
causing the existing file read to be silently skipped and docker_config
to always reset to {}
- Folded scalar `>` in set_fact converted the dict to a Python string
representation, which to_nice_json serialized as a JSON string instead
of an object
Fixes identified during 2026-04-13 power cut incident post-mortem.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,12 +35,16 @@
|
|||||||
state: directory
|
state: directory
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
|
|
||||||
|
- name: Check if daemon.json exists
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /etc/docker/daemon.json
|
||||||
|
register: docker_config_stat
|
||||||
|
|
||||||
- name: Lire la configuration Docker existante
|
- name: Lire la configuration Docker existante
|
||||||
ansible.builtin.command: "cat /etc/docker/daemon.json"
|
ansible.builtin.command: "cat /etc/docker/daemon.json"
|
||||||
register: docker_config_raw
|
register: docker_config_raw
|
||||||
ignore_errors: yes
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
when: (ansible.builtin.stat.path='/etc/docker/daemon.json').stat.exists
|
when: docker_config_stat.stat.exists
|
||||||
|
|
||||||
- name: Initialiser la variable de config Docker
|
- name: Initialiser la variable de config Docker
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
@@ -82,12 +86,7 @@
|
|||||||
|
|
||||||
- name: Ensure docker_config is a dictionary
|
- name: Ensure docker_config is a dictionary
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
docker_config: >
|
docker_config: "{{ docker_config if docker_config is mapping else {} }}"
|
||||||
{% if docker_config is mapping %}
|
|
||||||
{{ docker_config }}
|
|
||||||
{% else %}
|
|
||||||
{}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
- name: Écrire la configuration mise à jour
|
- name: Écrire la configuration mise à jour
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
|
|||||||
Reference in New Issue
Block a user