From 355ab11c4d968c365c123345c2fb42db1ce18a68 Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Tue, 14 Apr 2026 10:52:27 +0200 Subject: [PATCH] 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 --- .../factory/playbooks/system/system_docker.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ansible/arcodange/factory/playbooks/system/system_docker.yml b/ansible/arcodange/factory/playbooks/system/system_docker.yml index adcb0fe..d7f4f50 100644 --- a/ansible/arcodange/factory/playbooks/system/system_docker.yml +++ b/ansible/arcodange/factory/playbooks/system/system_docker.yml @@ -35,12 +35,16 @@ state: directory 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 ansible.builtin.command: "cat /etc/docker/daemon.json" register: docker_config_raw - ignore_errors: yes 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 ansible.builtin.set_fact: @@ -82,12 +86,7 @@ - name: Ensure docker_config is a dictionary ansible.builtin.set_fact: - docker_config: > - {% if docker_config is mapping %} - {{ docker_config }} - {% else %} - {} - {% endif %} + docker_config: "{{ docker_config if docker_config is mapping else {} }}" - name: Écrire la configuration mise à jour ansible.builtin.copy: