The Ansible Tour, Part 4: Nextcloud – Collabora, Push, Host Database and occ, Role by Role
Part 4 of the Ansible Tour: why each piece of Nextcloud exists, how it is deployed on K3s, configured with occ and updated safely.

🌐 Also available in: Deutsch · Français · Español · Italiano · Português · Nederlands · Polski
Part 4 of the Ansible Tour. After the blog in part 3, here comes the second application: Nextcloud (opens in a new tab). The series describes release v3.3.0 (opens in a new tab), with later changes added as addenda. What matches the blog is only mentioned briefly; the focus is on what is different.
In short: Part 4 of the Ansible (opens in a new tab) tour shows the second application: Nextcloud with Collabora (opens in a new tab) and push, for two groups of very different size, from the same code. Database and Redis run on the host here, Nextcloud, Collabora and the push service as Kubernetes objects, and settings are read, compared and only set when needed – plus a careful update playbook.
Nextcloud is a file cloud: files, calendars, contacts, team folders and – with Collabora – documents edited together in the browser. Two of the three servers run it, for groups of very different size, with the same code and different values in the inventory. The work is shared by next_mariadb and next_redis (database and cache on the host), next_k3s_deploy (Nextcloud, Collabora and the push service as Kubernetes objects), next_config (Nextcloud’s settings) and nextcloud_verify, plus the update playbook.
Table of Contents
🏗️ What runs, and why
A request takes the same path as on the blog: ingress, nginx sidecar, PHP-FPM in one pod. Everything around it is different:
- Two separate host directories for the application and the user data. A new image replaces the application files, the users’ files stay where they are and are backed up independently.
- MariaDB and Redis on the host, not in the cluster. The database is the heaviest and most valuable component; on the host it gets the full systemd sandbox, its own SELinux domain and no volume layer between data and disk. Redis holds the file locks: two sync clients that save the same file at the same moment must not corrupt it.
- Collabora Online, an office suite that runs on the server and is displayed in the browser. Nextcloud and Collabora talk via WOPI: the editor asks the file server for a file and to save a version, signed with a key.
- notify_push keeps a WebSocket connection to the clients open and reports changes. Without it every client asks every thirty seconds.
- A CronJob runs the background tasks every five minutes; previews are generated in advance by an app instead of on the first click.
🗄️ next_mariadb and next_redis: services on the host
MariaDB gets a systemd sandbox before it starts for the first time. That is why the role reloads systemd directly and not through a handler: a handler would run at the end of the play, and on a fresh server the database would start without the sandbox first. This sandbox was also the scene of the most important bug in September: NoNewPrivileges stopped MariaDB from entering its SELinux domain, and the database ran unconfined for five weeks although SELinux was enforcing. The MariaDB deep dive tells that story. Since 16 October 2026 MariaDB has its own /tmp in RAM; it must not be combined with PrivateTmp=yes, or the directory on disk silently wins.
Two smaller stories show how quiet bugs can be. The slow query log needs a directory that MariaDB does not create itself; without it the database ran with the slow log silently switched off – a diagnosis that looked switched on and collected nothing. And the exporter user got its privilege granted again on every run, because MariaDB reports REPLICATION CLIENT under its newer name BINLOG MONITOR and the role asked for the old one.
Nextcloud’s database user may log in only from the pod network. Even with a mistake in the firewall, MariaDB would refuse this login from anywhere else.
Redis listens on the host’s address so that the pods can reach it. At first only one firewall rule stood between the internet and Redis – and that a protection layer fails silently is no theory here: fail2ban once lay dead on the blog for two days without anyone noticing. Redis therefore has a password, which reaches Nextcloud through a secret. Since 26 October 2026 Redis comes from the AppStream module stream redis:7 instead of the EL9 default 6.2.
The takeaway: a database is easy to get running and hard to confine properly. After every hardening, ps -eZ shows whether it still runs in its domain.
🚀 next_k3s_deploy: Nextcloud, Collabora and push
Where a point describes a change, a link leads to the commit that made it.
The same structure as on the blog, with one difference in behaviour: it waits only when an object really changed. How does a pod reach a database outside the cluster? With a service without a pod selector and an Endpoints object filled by hand that points at the host. For Nextcloud, mariadb and redis are then ordinary names in the cluster.
The Nextcloud pod installs itself from environment variables on its first start against an empty database. Important in operation: these values are read only this one time. After that the credentials are in config.php, and changing the secret alone changes nothing. For a new major version the entrypoint runs the upgrade before PHP-FPM starts; that can take minutes, so the startup probe allows ten minutes before the liveness probe steps in. Three numbers have to fit together for uploads up to 2 GB: the PHP limit, the limit in the nginx sidecar and the one at the ingress. The template says so exactly where the values are set.
My own settings come as custom.config.php from a ConfigMap, next to Nextcloud’s config.php: language, session lifetime, cache and locking, previews, the trusted proxy. Later configuration files win, so a value set here cannot drift through the web interface. The bytecode cache gets 256 MB and room for 20,000 files: with all its apps an installation has up to 17,800 PHP files, and the old limit of 10,000 made part of them recompile on every request.
Since 26 October 2026 the Nextcloud pod rolls without downtime as long as the image stays the same – for configuration changes and rebuilds of the same tag. When the image changes it stays with Recreate, because the entrypoint then copies new code and runs the upgrade; meanwhile no old pod may serve from the same directory. The role decides this on every run and switches back to rolling update afterwards. → ce50d16 (opens in a new tab)
Collabora signs every WOPI request with a key that Nextcloud verifies. The current image no longer creates this key itself; it ran without one, and Nextcloud could not verify that requests really came from Collabora. The role creates it once and pipes it from openssl straight into a secret – the private key never touches the disk. Collabora is the one container that does not drop all capabilities: it builds its own sandbox for every document and needs rights for that which a guess from the documentation could break in a way that only shows when a user opens a file. Its probes ask for a two-byte page instead of the 43 KB discovery document: the kubelet closes the connection after 10 KB, and Collabora logged every such close as two errors. On the larger server Collabora may use six of eight cores since 26 October 2026; while generating previews it ran into the old limit of four.
The network rule has a different goal on Nextcloud than on the blog. Collabora processes arbitrary documents that users upload – a more plausible entry point than most PHP code – and has no reason ever to talk to MariaDB or Redis. The rule therefore allows it only requests from the ingress and Nextcloud, DNS and the WOPI callbacks on port 443 of the host, explicitly not 3306 and 6379 on the same address.
Ingress and login. The same structure of master and minions as on the blog, with a minion for /push/ carrying WebSocket headers. Its name matters: the controller sorts regex locations by the name of the ingress, and the wrong name let Nextcloud’s catch-all route answer first during the first rollout. On 26 October 2026 it also turned out that the rate limit only knew /login – but Nextcloud sends its form to /index.php/login. Since July neither the rate limit nor the fail2ban filter had seen a single real login; now both know both paths.
Apps and push. The inventory lists only the deliberate deviations for apps: which stay forced off and which should be on. If an app has no compatible version yet after a major upgrade, it stays off, and the role reports exactly which one – instead of aborting at the first error. The notify_push binary ships with an app; its version is therefore an annotation in the pod template, so that an app update rolls out the pod again and binary and app can never drift apart.
The takeaway: a path you take for the login page is not necessarily the one the application uses. Test protection rules with what the browser really sends.
⚙️ next_config: read, compare, set
Nextcloud’s settings are set with occ, following one pattern: read the current value, compare it with the desired one, write only on a mismatch. A run without changes reports nothing, and a value someone changed in the web interface is reset and shows up as a change. That makes the drift check meaningful for application settings too, not just for files. The mail settings used to be rewritten all nine on every run and still reported “ok” – a changed SMTP password never showed up.
The most instructive file of the role is the password policy: at least 12 characters and a check against known leaked passwords, for which only the first five characters of the hash leave the server. When the app was switched on on one server, every user with a password older than 300 days was locked out, the admin included. A setting from the old server had lain unnoticed in the database until the app that reads it was switched on. Since then the role sets every key of the policy explicitly, including the ones that are meant to be off.
The takeaway: before switching on an app, read which configuration it already has. After a migration there is often more there than you think.
🔄 nextcloud-update.yml: an update with care
A file cloud people depend on deserves a careful update. The playbook refuses to run without --limit and on an instance that is not healthy – in maintenance mode or with a pending database upgrade. Then it restarts only deployments whose image was rebuilt upstream, runs occ upgrade and the app updates, and restarts the pod a second time afterwards. The reason: Nextcloud runs with opcache.validate_timestamps=0, so PHP never checks whether a file changed. Without that restart the old code would keep running, security fixes included.
If something fails, the rescue part shows status, pods and the end of nextcloud.log and makes a careful decision: it leaves maintenance mode only if the upgrade itself has completed. Otherwise users would land on a half-updated instance.
The takeaway: a cache that never re-checks files is fast and needs a restart after every code update. That belongs in the update procedure, not in someone’s memory.
🛠️ Running it
- Updates:
ansible-playbook nextcloud-update.yml --limit <host>, with--checkfirst. A new major version is a new image tag inversions.ymland a full run – always one major version at a time, with release notes and a snapshot first. - “Office could not be loaded”, a retry works: a short hiccup between browser, Collabora and Nextcloud. If it happens often, Collabora needs more pre-started processes or more memory.
- Maintenance mode after a failed update: first
occ status; if an upgrade is pending, runocc upgradeand read its output, only then switch maintenance mode off. - Users locked out by the password policy:
occ config:app:get password_policy expirationmust be 0. - The disk fills up: the alert comes at 80 percent. The trash keeps 180 days; previews can be regenerated and cleaned with
occ preview:cleanup, never withrm.
🎯 Conclusion: The lessons of part 4
- What is valuable goes on the host, what is replaceable into the cluster – and a service without a selector gives the host services a name in the cluster.
- Values from the first installation are read only once; after that
config.phpapplies. - A network rule follows the most likely entry point, here Collabora.
- Read, compare, set – for application settings too, so the drift check sees them.
- Before switching on an app, read its existing configuration.
🧭 Where the tour goes next
With part 4 both applications are covered. Part 5 gathers all security roles in one place, part 6 the monitoring. The technology under this part is explained in the Nextcloud deep dive.
Addendum (28 November 2026): The www_k3s repository is now archived and has been split: the Nextcloud part lives on in nextcloud_k3s (opens in a new tab), the blog server in www_hugo (opens in a new tab). The links in this post point to the state at the time and still work.
