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.
101 lines
3.3 KiB
YAML
101 lines
3.3 KiB
YAML
---
|
|
- name: Ensure the Tandoor data directories exist
|
|
ansible.builtin.file:
|
|
path: "{{ host_directory }}/{{ item }}"
|
|
state: directory
|
|
owner: "{{ podman_user }}"
|
|
group: "{{ podman_user }}"
|
|
mode: '0755'
|
|
loop:
|
|
# mediafiles is irreplaceable. The other two are regenerated and bind-mounted because the image expects them.
|
|
- mediafiles
|
|
- staticfiles
|
|
- externalfiles
|
|
|
|
# systemd reads it through EnvironmentFile= before the unit starts, and it holds SECRET_KEY and the Postgres password.
|
|
- name: Write the environment file
|
|
ansible.builtin.template:
|
|
src: tandoor.env.j2
|
|
dest: "{{ host_directory }}/.env"
|
|
owner: "{{ podman_user }}"
|
|
group: "{{ podman_user }}"
|
|
mode: '0600'
|
|
notify: Restart Tandoor
|
|
|
|
- name: Install the Tandoor Quadlet unit
|
|
ansible.builtin.template:
|
|
src: tandoor.container.j2
|
|
dest: "{{ quadlet_dir }}/{{ container_name }}.container"
|
|
owner: "{{ podman_user }}"
|
|
group: "{{ podman_user }}"
|
|
mode: '0644'
|
|
notify:
|
|
- Reload systemd user units
|
|
- Restart Tandoor
|
|
|
|
- name: Start Tandoor
|
|
block:
|
|
- name: Start Tandoor
|
|
ansible.builtin.systemd_service:
|
|
name: "{{ unit_name }}"
|
|
scope: user
|
|
state: started
|
|
daemon_reload: true
|
|
rescue:
|
|
# systemd only reports "control process exited with error code", so pull the real reason.
|
|
- name: Collect Tandoor diagnostics
|
|
ansible.builtin.command: "{{ item }}"
|
|
loop:
|
|
- "systemctl --user status {{ unit_name }} --no-pager"
|
|
- "journalctl --user -u {{ unit_name }} --no-pager -n 40"
|
|
- "podman logs --tail 40 {{ container_name }}"
|
|
register: tandoor_diag
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Show Tandoor diagnostics
|
|
ansible.builtin.debug:
|
|
msg: "{{ tandoor_diag.results | map(attribute='stdout') | list }}"
|
|
|
|
- name: Fail
|
|
ansible.builtin.fail:
|
|
msg: "Tandoor did not start — see the diagnostics above."
|
|
|
|
# Quadlet honours [Install] WantedBy=, so `systemctl --user enable` is not needed on a generated unit.
|
|
- name: Verify Tandoor is running
|
|
ansible.builtin.command: "systemctl --user is-active {{ unit_name }}"
|
|
register: tandoor_active
|
|
changed_when: false
|
|
failed_when: tandoor_active.stdout != 'active'
|
|
|
|
# The environment file asks for `db`; the container name is checked too because the network provides it.
|
|
- name: Confirm Tandoor can resolve its database
|
|
ansible.builtin.command: >-
|
|
podman exec {{ container_name }} getent hosts {{ item }}
|
|
loop:
|
|
- "{{ postgres_container }}"
|
|
- db
|
|
register: tandoor_db_lookup
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Report database resolution
|
|
ansible.builtin.debug:
|
|
msg: >-
|
|
{{ item.item }} resolves as
|
|
{{ item.stdout | default('(no answer)') }}
|
|
loop: "{{ tandoor_db_lookup.results }}"
|
|
|
|
# `is-active` only says the container is running. Tandoor migrates before gunicorn answers, and its nginx returns 502 until then.
|
|
# The probe uses python3 because the Django image guarantees it and may not ship curl or wget.
|
|
- name: Wait for Tandoor to serve HTTP
|
|
ansible.builtin.command: >-
|
|
podman exec {{ container_name }}
|
|
python3 -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1/', timeout=5)"
|
|
register: tandoor_http
|
|
until: tandoor_http.rc == 0
|
|
retries: 24
|
|
delay: 5
|
|
changed_when: false
|
|
failed_when: tandoor_http.rc != 0
|