The Ansible Tour, Part 2: The Platform – From a Bare AlmaLinux to a Kubernetes Cluster
Part 2 of the Ansible Tour: packages, kernel settings, mail, nightly updates, K3s, Helm, cert-manager, ingress and Calico – role by role.

🌐 Also available in: Deutsch · Français · Español · Italiano · Português · Nederlands · Polski
Part 2 of the Ansible Tour. Part 1 explained how the repository is built; this part starts at the very bottom. The series describes release v3.3.0 (opens in a new tab), with later changes added as addenda.
In short: Part 2 of the Ansible (opens in a new tab) tour starts at the very bottom: a bare AlmaLinux (opens in a new tab) cloud image becomes a patched base system that sends mail, updates itself at night and rotates its logs – with a single-node Kubernetes (opens in a new tab) cluster on top, including Helm, Let’s Encrypt certificates and an ingress. That is the platform the blog and Nextcloud stand on, including a component that never did anything.
Every server here starts as a plain AlmaLinux 9 cloud image: a minimal Linux, a root login, nothing else. At the end of this part it is a patched base system that sends mail, updates itself at night and rotates its logs – and runs a single-node Kubernetes cluster with Helm, automatic Let’s Encrypt certificates and an ingress controller. That is the platform the blog and Nextcloud stand on. Almost all of it is the same for both.
Table of Contents
🖥️ Before the first role: server, distribution, size
All three servers are rented virtual machines (VPS) at two different providers, so an outage or an account problem at one of them does not take everything down. What matters when choosing is less the price than the points that count in operation: a data centre in the EU with a data processing agreement, fixed IPv4 and IPv6 addresses, a web console that still works when SSH no longer does, and snapshots before risky changes. Test the console before you need it: with hardened SSH and a firewall it is the way back after a mistake of your own.
The roles are written for AlmaLinux 9 and nothing else. The reasons: about ten years of security updates per major version, updates that carry a type (which allows installing only security fixes automatically), SELinux enforcing out of the box with a policy for containers, and the CIS benchmark and most tools appear for this family first. AlmaLinux 10 comes later: for 9, EPEL, the K3s SELinux policy and third-party repositories are mature, and security updates run until 2032.
| Server | vCPU | RAM | Disk | RAM at idle |
|---|---|---|---|---|
| Blog | 4 | 8 GB | 240 GB | about 2.5 GB |
| Small Nextcloud (few users) | 6 | 12 GB | 200 GB | about 3 GB |
| Large Nextcloud (about 150 users) | 8 | 24 GB | 600 GB | about 4 GB |
The platform from this part – K3s, the container runtime, the system pods, cert-manager, the ingress – takes about 1.3 to 1.5 GB of that, Prometheus and Grafana about 0.5 GB. The rest is the application and the file cache, which Linux fills with all free memory. None of the servers has swap: a server that starts swapping is already too small, and the memory alert from part 6 reports that earlier. Before the first run a server needs only the image, an SSH key for root, its entries in the inventory and DNS records pointing at it – cert-manager can only get a certificate for a name that resolves to the server.
The takeaway: start small, measure with the monitoring and grow when the numbers say so. Most providers allow that without reinstalling.
📦 blog_packages and next_packages: from image to base system
The only pair of roles in the repository that does the same job in two variants: the blog runs everything in containers, a Nextcloud host additionally runs MariaDB and Redis directly on the host and needs two more repositories and two more services for that. The role first sets a real hostname – a cloud image is called localhost, and five nightly reports from “localhost” are useless. Then it sets up the repositories (EPEL; on Nextcloud also CRB and MariaDB Community with a pinned version series), installs all updates and the base packages.
There is no suitable Ansible module for repositories, so the role uses commands with a pattern that recurs throughout the repository: ask first, then act. One task only reads (for example dnf repolist) and never reports a change; a second task runs only if the answer shows that something is missing. The first run reports a change, every later one none – the precondition for the idempotence from part 1.
The system update leaves kernels out, and the reason is instructive. The SSH hardening from part 5 starts every SSH session with ProtectKernelModules in a private view of the file system in which the kernel module directory is empty and read-only. Nobody who logs in via SSH can load a module – Ansible included, and a new kernel has to put its modules exactly there. Kernels therefore arrive at night through dnf-automatic, which runs as a systemd timer outside any SSH session. For the same reason the role uses systemd-run to check whether a reboot is needed after an image update: only a process that systemd itself starts sees the real file system.
Finally the role switches off what the server does not use: firewalld, the NFS and LDAP helpers. What is masked does not even start as a dependency of another service.
The takeaway: a hardening also applies to the tool that set it up. If you do not want to work around it, move the work to where it belongs – here into a systemd timer.
🧮 common_sysctl: kernel parameters
Two files in /etc/sysctl.d/: one for speed (TCP BBR instead of CUBIC, larger queues for incoming connections, higher inotify limits for K3s, earlier write-back of dirty pages) and one for security, the network items of the CIS benchmark (no ICMP redirects, no source routing, SYN cookies, restricted ptrace). Most instructive is what it leaves out: a usual CIS profile switches IP forwarding off and strict reverse path filtering on. On a Kubernetes node both would break the cluster – pods are reached through routing on the host. A dated comment in the template makes sure nobody “fixes” this by following the benchmark blindly.
Because the SSH session also sees /proc/sys read-only, the role sets the values through systemd-run, on every run: a handler only reacts to changed files, not to someone having changed a value at runtime with sysctl -w. Since 26 October 2026 the role also puts psi=1 on the kernel command line: the EL9 kernel ships with pressure stall information (PSI) switched off, which is why the “Pressure” panel in Grafana stayed empty.
The takeaway: a benchmark is written for a general server. Where it harms a Kubernetes node, deviate with a reason – and write the reason down.
✉️ common_msmtp: mail without a mail server
Where a point describes a change, a link leads to the commit that made it.
Half of the protection mechanisms report by mail: scanners, the update job, the SSH login alert, the watchdog. A mail server would be one more service with an open port. msmtp is the opposite: no daemon, no queue. A program calls sendmail, msmtp hands the mail to an external SMTP account and exits. The role takes the credentials from the same inventory values Nextcloud uses and hides the output of the template task with no_log, because the file contains the password.
Two mistakes from October 2026 show why a mail path needs tests. Cron sent mail with the sender root, which the provider rejected – the messages were lost for weeks until the role fixed the sender. And the SMTP password contained a #, which started a comment in Grafana’s configuration. Since then Monit checks msmtp.log for every rejected mail, and Grafana sends a mail once a week that must always arrive. → 5ab9bed (opens in a new tab), 6d50c21 (opens in a new tab)
The takeaway: a mail path that carries only alerts is noticed only when an alert is missing. It needs a regular sign of life.
🌙 common_dnf_automatic: updates at night
dnf-automatic installs only packages marked as security fixes every night; everything else stays a planned run with the playbook. The interesting part is the night’s schedule, because several jobs depend on each other:
| Time | What |
|---|---|
| 00:00 | AIDE checks the system files against its baseline |
| 01:00–02:00 | Security updates are installed |
| 03:30 | Reboot if an update needs one |
| 03:45 | Services still running replaced code are restarted |
| 04:00 | The AIDE baseline is renewed |
| 04:30 | ClamAV scans the user data (Nextcloud) |
| 06:00 | Warning mail if a reboot is still pending |
The shipped timer ran at 06:00 – after the reboot window and after the AIDE renewal. Every security update therefore showed up as an AIDE alert the next night, and a new kernel waited almost a day for its reboot. The role moves the timer with a systemd drop-in. A trap hides in an empty line: OnCalendar= without a value first clears the shipped list; without it the timer would run at 01:00 and at 06:00.
The takeaway: nightly jobs form a chain. Moving one of them means checking the whole order.
🗂️ common_logrotate
Grafana and Prometheus ship without rotation rules, fail2ban and rkhunter with incomplete ones. The role adds them. The one directive to understand is postrotate: a running program keeps its log file open and keeps writing into the renamed file until it is told to reopen.
☸️ common_k3s: Kubernetes on one server
Why Kubernetes on a single server at all? Every application is described as a set of objects in the repository and can be rebuilt identically on a new server; an update means changing an image tag, and rolling back works the same way; every application has its own namespace with its own network rules and resource limits; and both stacks are deployed the same way. The price is complexity and about 1.5 GB of memory. K3s is the fitting distribution: one binary with API server, scheduler, kubelet, containerd and Flannel. What it brings beyond that is switched off – Traefik, ServiceLB and local-storage. What does not run cannot be attacked.
The configuration is written before K3s starts for the first time: an audit log for the API server (who did what; for secrets only who, never the content), a limit on events per second, and the admission plugins. That is where one of the most instructive traps lay: in Kubernetes enable-admission-plugins adds to the default list, in K3s it replaces K3s’s own setting (NodeRestriction). With only EventRateLimit, NodeRestriction silently disappeared – the plugin that keeps a compromised kubelet to its own objects. A new kube-bench run found it.
Binary and install script are pinned to the same version and come from the GitHub release, not from get.k3s.io, which always serves the latest script and answered with HTTP 500 for a while during the first installation of a server. The role reads the installed version and downloads only on a mismatch. Until 19 October 2026 the download lacked force: true: Ansible skipped it because the file already existed, and no version bump since the first installation ever arrived, without anything reporting it. Since then a check at the end of every run compares the version the kubelet reports with the pin.
Because every role after this one talks to the cluster, the role does not wait for the end of the play to restart K3s: meta: flush_handlers runs the restart right away, and a task waits until the API answers – with retries instead of a fixed pause.
cert-manager gets the certificates from Let’s Encrypt and renews them. It is installed with Ansible’s Helm module, which updates only on a real difference; the earlier shell command reported a change on every run. Before the ClusterIssuer can be created, Kubernetes has to know the new object type – the role waits for that. And because the F5 ingress controller silently ignores a second ingress for the same hostname, cert-manager creates its challenge ingress as a “minion” that is merged into the application’s ingress.
The ingress controller is the only thing that answers on ports 80 and 443: a pod with hostNetwork, configured for TLS 1.2 and 1.3, HTTP/2, no version number in the server header, and the zones for rate-limiting the login pages. One detail cost a debugging session: for a hostname without a certificate this controller simply closes the connection – in the browser indistinguishable from a server that is down. A self-signed fallback certificate makes the difference visible. Since 26 October 2026 its access log also records the content type and length of every request.
Finally the default account of every namespace no longer gets an API token mounted: a web application does not need to talk to the API server, and a compromised one should not be able to.
The takeaway: an update task that reports “ok” has not necessarily updated anything, and a flag with the same name does not necessarily do the same in K3s as in Kubernetes. Check what runs, not what is configured.
Calico: the component that never did anything
Until 19 October 2026 Calico ran next to K3s to enforce the NetworkPolicies. A test showed it had never matched a single one: Calico’s agent recognises pods only by interfaces named cali*, while K3s’s Flannel names them veth*. The enforcement had come from K3s’s built-in policy controller all along. The earlier observation “the deny-all rule only worked with Calico” cannot have been right. Calico is gone; the K3s deep dive tells the whole story.
The takeaway: a security component only works once a test shows that it blocks something. That it runs only shows that it uses memory.
🛠️ Running it
Most of this part runs by itself. Two mails belong to it: “Rebooting now after security update” means a kernel or core library arrived at night and the server rebooted at 03:30 – nothing to do. “WARNING: reboot still required” means the automatic reboot did not happen; look at journalctl -b -1 and reboot by hand.
- Host packages that are not security fixes only come with the package role (
--tags blog_packagesornext_packages). - K3s, Helm and the charts: change the pin in
versions.yml, drift check with--tags common_k3s, then the real run. K3s always one minor version at a time; read the release notes first and take a snapshot. - Check the NetworkPolicies: a pod from another namespace must not reach a protected port.
- Kernel parameters: change the template,
--tags common_sysctl. Never “fix” IP forwarding or reverse path filtering by the textbook.
🎯 Conclusion: The lessons of part 2
- A hardening applies to Ansible too – work it forbids belongs in a systemd timer or behind
systemd-run. - Leave a benchmark with a documented reason where it harms a Kubernetes node.
- Nightly jobs form a chain; their order is part of the configuration.
- After an update, the running version counts, not the task’s message.
- Prove a security component with a test, not with its status.
🧭 Where the tour goes next
The platform is in place: a patched base system with mail, nightly updates and rotated logs, and a Kubernetes cluster with certificates, a front door and network rules that work. Part 3 puts the blog on it, part 4 Nextcloud. SSH, the firewall, hardening and SELinux are in part 5.
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.
