The role had grown machinery that the problem does not require. Removed: - The init-sync lock pre-create. It guarded against one file in the webroot being owned by a subuid, which is cosmetic: the file is 0644, so it is readable and removable by host-side tools either way. - The image ID read/pull pair. No other service playbook pulls an image, and the update path is two commands the readme now spells out. - redis-session.ini.j2 and its three variables. The mount is load-bearing -- the entrypoint cannot write into the image's conf.d and dies trying -- but the template is not: the entrypoint writes that file itself on every start. One touched empty file and one Volume line replace the template and the variables. - The config.php stat, the wizard note, the maintenance-mode wait, the occ status report, the getent checks, the timer report. The installed/not-installed branching existed only because the readiness gates were written for an installed instance; with a gate that fits both, none of the branching is needed. - Comments that narrated this play's earlier runs rather than the system. What is left is four tasks before the start, a start-plus-gate block whose rescue collects the journal, and four tasks for the background-job timer: 149 lines and about 130 of them code, against 313 before. The readme loses its migration-era bulk for the same reason and is 297 lines, in line with the other services'. The one gate is now Nextcloud's own status.php inside the container. It answers only once the entrypoint has finished -- including any `occ upgrade`, which runs before Apache starts, so an update in progress is waited out rather than missed -- it reports `installed` either way, so a fresh webroot and an installed instance go through the same check, and it carries `maintenance` as well, which is the one state a probe would otherwise call healthy while every page returned 503.
44 lines
1.8 KiB
YAML
44 lines
1.8 KiB
YAML
---
|
|
# Attach this app's network to the shared Postgres unit, and make sure the
|
|
# database exists.
|
|
|
|
- name: Attach Nextcloud to Postgres
|
|
ansible.builtin.include_tasks: "{{ playbook_dir }}/../postgres/roles/attach/tasks/main.yaml"
|
|
|
|
# The restart that joins Postgres to nextcloud_net is a handler, so by default it
|
|
# would run at the end of the play — after the app has started and failed to
|
|
# resolve `db`. Flushing first also applies the Caddy restart queued by the
|
|
# register pre_task. Nothing is pending on later runs.
|
|
- name: Apply the network change before starting Nextcloud
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
# Postgres ships one default database and only this app knows the name of its own,
|
|
# so on a fresh cluster the installer would otherwise fail with "database
|
|
# nextcloud does not exist". The retry is for the restart the flush above may have
|
|
# just done.
|
|
- name: Check whether the {{ pg_database }} database exists
|
|
ansible.builtin.command: >-
|
|
podman exec -e PGPASSWORD={{ pg_password }} {{ postgres_container }}
|
|
psql -U {{ pg_user }} -d postgres -tAc
|
|
"select datname from pg_database where datname = '{{ pg_database }}'"
|
|
register: nextcloud_db
|
|
until: nextcloud_db.rc == 0
|
|
retries: 12
|
|
delay: 5
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Fail if the shared Postgres is not reachable
|
|
ansible.builtin.assert:
|
|
that: nextcloud_db.rc == 0
|
|
fail_msg: >-
|
|
{{ postgres_container }} did not answer. Run postgres/playbook.yml on this
|
|
host first — this play attaches to that cluster and creates its own database
|
|
in it.
|
|
|
|
- name: Create the {{ pg_database }} database
|
|
ansible.builtin.command: >-
|
|
podman exec -e PGPASSWORD={{ pg_password }} {{ postgres_container }}
|
|
createdb -U {{ pg_user }} -O {{ pg_user }} {{ pg_database }}
|
|
when: nextcloud_db.stdout | trim | length == 0
|