--- # 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 caddy/playbook.yml has # not run. # # The marker is the same one the retired nginx-menu playbook wrote per hostname, # so a Site cut over from it has its block replaced in place rather than a second # block for one address appended, which would make Caddy refuse the whole config. - 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: true owner: '{{ podman_user }}' group: '{{ podman_user }}' mode: '0644' notify: Reload Caddy