Files
playbooks/postgres/roles/attach/tasks/main.yaml
T
tanshu 476a6d7cd0 Cut the comment bloat from the Podman playbooks
Comment blocks now stay within three lines and explain only the non-obvious. Long histories, include examples, and commented-out code are gone. No task, key, or value changed; the only data change is comment text inside the generated unit files.
2026-10-18 22:10:57 +05:30

55 lines
2.1 KiB
YAML

---
- name: "Check that the {{ network_name }} network unit exists"
ansible.builtin.stat:
path: "{{ quadlet_dir }}/{{ network_name }}.network"
register: postgres_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: postgres_attach_network.stat.exists
fail_msg: >-
{{ quadlet_dir }}/{{ network_name }}.network does not exist, so attaching
it to Postgres would break the postgres unit. Create the network first
(caddy/roles/register does it), then include this file.
- name: Ensure the Postgres Quadlet drop-in directory exists
ansible.builtin.file:
path: "{{ quadlet_dir }}/{{ postgres_container | default('postgres') }}.container.d"
state: directory
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: '0755'
- name: "Attach {{ network_name }} to Postgres"
ansible.builtin.copy:
dest: >-
{{ quadlet_dir }}/{{ postgres_container | default('postgres') }}.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
# {{ postgres_container | default('postgres') }} on the next daemon-reload.
[Container]
Network={{ network_name }}.network
notify: Restart Postgres
# 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 {{ postgres_container | default('postgres') }} the shared 'db' alias"
ansible.builtin.copy:
dest: >-
{{ quadlet_dir }}/{{ postgres_container | default('postgres') }}.container.d/10-network-aliases.conf
owner: "{{ podman_user }}"
group: "{{ podman_user }}"
mode: '0644'
content: |
# Shared container aliases for {{ postgres_container | default('postgres') }}.
# Managed by Ansible (the service playbooks that use it). Do not edit.
[Container]
NetworkAlias=db
notify: Restart Postgres