--- - name: "Check that the {{ network_name }} network unit exists" ansible.builtin.stat: path: "{{ quadlet_dir }}/{{ network_name }}.network" register: valkey_attach_network # A drop-in naming a missing network breaks unit generation with an unrelated # error, so fail here instead. - name: "Fail if {{ network_name }} has no network unit" ansible.builtin.assert: that: valkey_attach_network.stat.exists fail_msg: >- {{ quadlet_dir }}/{{ network_name }}.network does not exist, so attaching it to Valkey would break the valkey unit. Create the network first (caddy/roles/register does it), then include this file. - name: Ensure the Valkey Quadlet drop-in directory exists ansible.builtin.file: path: "{{ quadlet_dir }}/{{ valkey_container | default('valkey') }}.container.d" state: directory owner: "{{ podman_user }}" group: "{{ podman_user }}" mode: '0755' - name: "Attach {{ network_name }} to Valkey" ansible.builtin.copy: dest: >- {{ quadlet_dir }}/{{ valkey_container | default('valkey') }}.container.d/50-{{ network_name }}.conf owner: "{{ podman_user }}" group: "{{ podman_user }}" mode: '0644' content: | # Added by {{ network_name }}. Deleting it detaches the network from # {{ valkey_container | default('valkey') }} on the next daemon-reload. [Container] Network={{ network_name }}.network notify: Restart Valkey # NetworkAlias applies to every network, so one shared file holds the fixed # alias. Two services writing their own would pass --network-alias twice. - name: "Give {{ valkey_container | default('valkey') }} the shared 'redis' alias" ansible.builtin.copy: dest: >- {{ quadlet_dir }}/{{ valkey_container | default('valkey') }}.container.d/10-network-aliases.conf owner: "{{ podman_user }}" group: "{{ podman_user }}" mode: '0644' content: | # Shared container aliases for {{ valkey_container | default('valkey') }}. # Managed by Ansible (the service playbooks that use it). Do not edit. [Container] NetworkAlias=redis notify: Restart Valkey