--- # Append this site's block to the shared Caddyfile. # # The Caddyfile is a bind mount into the Caddy container, so Caddy sees the # change as soon as the file is written; the handler only asks Caddy to re-read # it. That is a reload, not a restart, so the other hosted sites are untouched. # # blockinfile is idempotent on its own via the marker, so there is no need to # slurp the file and compare first — which also matters because slurp *fails* # when the Caddyfile does not exist yet, on a host where the Caddy playbook has # not run. # # The marker is stable, so re-runs replace this site's block in place rather than # appending a second copy of it. - name: "Add the {{ host }} site block to the Caddyfile" ansible.builtin.blockinfile: path: "{{ caddyfile_path }}" marker: "# {mark} Ansible managed Caddy snippet for {{ host }}" block: "{{ snippet_block }}" create: yes owner: "{{ podman_user }}" group: "{{ podman_user }}" mode: '0644' notify: Reload Caddy