Skip to content

Homelab Ansible

This repository runs Ansible playbooks against the hosts in ansible/inventory/hosts.yml.

Set up the environment

cd ansible
source .venv/bin/activate
ansible-galaxy collection install -r requirements.yml
ansible-inventory --graph

Ansible source, inventories, playbooks, and roles remain under ansible/.

Run a playbook

ansible-playbook playbooks/maintenance.yml

For hosts that use sudo instead of a root connection, prompt for the sudo password:

ansible-playbook playbooks/docker.yml --ask-become-pass

To run against one host or group, use:

ansible-playbook playbooks/maintenance.yml -e target_hosts=my-host
ansible-playbook playbooks/maintenance.yml -e target_hosts=proxmox_hosts

Inventory

inventory/hosts.yml is the default inventory. Edit it to add, move or remove a host. Ansible needs no other service to read it.

linux_hosts holds proxmox_hosts, k3s_cluster and standalone_linux_hosts. Each role also has a group: grafana_alloy_hosts, opentelemetry_collector_hosts, docker_hosts, hermes_agent_hosts and pbs_hosts. A playbook run without target_hosts changes every host in its group, so add a host to a role group only when it should run that role.

The agent, Android emulator and Nori hosts have their own inventory files. Their runbooks pass them with -i.

Playbooks

File What it does Default target
playbooks/maintenance.yml Updates Linux hosts, sets timezone, optional reboot linux_hosts
playbooks/alloy.yml Installs Grafana Alloy grafana_alloy_hosts
playbooks/agentos.yml Configures hosts for coding agents. Use -i inventory/agentos.yml agentos_hosts
playbooks/opentelemetry.yml Installs a host OpenTelemetry Collector for system metrics, hardware sensors and journald logs opentelemetry_collector_hosts
playbooks/pbs.yml Installs the OpenTelemetry Collector on PBS. It ships the journal and counts failed tasks and panics for the PBS alerts pbs_hosts
playbooks/docker.yml Installs Docker docker_hosts
playbooks/ubuntu-lts-upgrade.yml Upgrades Ubuntu Docker hosts to the latest supported LTS, then refreshes Docker packages docker_hosts
playbooks/proxmox-ntp.yml Installs and starts chrony on Proxmox and adds the LAN time server by address proxmox_hosts
playbooks/proxmox-host-baseline.yml Caps the ZFS cache, schedules SSD trim, disables stale units, removes the dead rsyslog forwarding rule, sets journal limits, adds static host names and sets the backup fleecing default proxmox_hosts
playbooks/proxmox-network.yml Standardizes bridge names while mapping physical NICs per host. Requires explicit write confirmation and does not reload networking. proxmox_hosts
playbooks/proxmox-sdn.yml Installs Proxmox SDN packages proxmox_hosts
playbooks/proxmox-pve9-prereqs.yml Prepares Proxmox hosts for PVE 8→9 by updating apt suites to Trixie/PVE 9, removing duplicate legacy Proxmox apt entries, updating existing Ceph repositories to Squid, optionally writing deb822 Debian sources, and installing CPU microcode (intel-microcode or amd64-microcode) when needed. It does not touch guests. proxmox_hosts
playbooks/proxmox-shutdown.yml Powers off every guest and node in order. A dry run unless proxmox_shutdown_execute=true. Follow the power runbook. proxmox_hosts
playbooks/k3s-check-time.yml Shows time and NTP status k3s_cluster
playbooks/k3s-clear-pod-logs.yml Truncates k3s pod logs k3s_cluster
playbooks/ping.yml Tests host access linux_hosts
playbooks/check-kernel.yml Prints kernel version linux_hosts
playbooks/resize-lvm-disk.yml Grows an Ubuntu LVM root disk must set target_hosts
playbooks/k8s-dns-record.yml Creates a DNS A record from localhost localhost

The OpenTelemetry playbook installs a pinned otelcol-contrib package. The collector reads host metrics and new journald entries and sends them over OTLP HTTP straight to Mimir and Loki. The Proxmox nodes are in opentelemetry_collector_hosts. The endpoints and the Mimir tenant are in inventory/group_vars/opentelemetry_collector_hosts.yml:

otelcol_mimir_endpoint: https://mimir.example.net/otlp
otelcol_mimir_tenant: monitoring
otelcol_loki_endpoint: https://loki.example.net/otlp

Mimir shows each host as job otelcol_service_name with the inventory name as the instance. Loki indexes the same two values as service_name and service_instance_id. Each log line is the journal message. The unit, the syslog identifier and the transport are attributes.

The host metrics receiver reads no temperatures, SMART attributes, ZFS pool usage, or LVM thin pools. With otelcol_node_exporter_enabled: true the role installs Debian's prometheus-node-exporter, bound to localhost, with the hwmon, cpu, and local filesystem collectors. With otelcol_node_exporter_storage_health_enabled: true it also runs a systemd timer that writes SMART wear/health, ZFS pool capacity and error counts, and LVM thin-pool usage to /run/prometheus-node-exporter (tmpfs) for the textfile collector. The collector scrapes it under job integrations/node_exporter and filters metrics through otelcol_node_exporter_metric_regex. otelcol_node_exporter_drivetemp: true loads the drivetemp kernel module, which SATA disks need to report a temperature.

TLS verification is on. Mimir and Loki take the data without credentials on the LAN. If that changes, read the headers from OpenBao into otelcol_exporter_headers, never into the checked-in defaults. Kubernetes node telemetry stays with the GitOps-managed collector from ADR 004.

Use the host OpenTelemetry Collector runbook to verify a rollout or remove the collector from a host.

Use common playbooks

To update hosts and reboot only if needed, run:

ansible-playbook playbooks/maintenance.yml -e common_maintenance_reboot_if_required=true

To install the QEMU guest agent, run:

ansible-playbook playbooks/maintenance.yml \
  -e target_hosts=my-vm \
  -e common_maintenance_install_qemu_guest_agent=true \
  -e common_maintenance_apt_upgrade=false

Upgrade the Docker VM from Ubuntu 20.04 to the latest LTS supported by the Ubuntu LTS upgrader, 24.04 by default. Run the playbook against one host at a time. It performs each required LTS hop and reboots between hops. It then reruns the Docker role so the APT repository and packages match the new Ubuntu codename.

ansible-playbook playbooks/ubuntu-lts-upgrade.yml --ask-become-pass -e target_hosts=docker

Only override the target after Ubuntu marks a newer LTS as supported in meta-release-lts.

ansible-playbook playbooks/ubuntu-lts-upgrade.yml \
  --ask-become-pass \
  -e target_hosts=docker \
  -e ubuntu_lts_upgrade_target_version=26.04

To prepare one Proxmox node for the PVE 8→9 apt upgrade without changing VMs or CTs, run:

ansible-playbook playbooks/proxmox-pve9-prereqs.yml -e target_hosts=pve

The playbook follows the Proxmox VE 8→9 repository migration in the upgrade guide. It changes existing Debian apt sources from Bookworm to Trixie and points the Proxmox VE repository at PVE 9. It removes legacy list-style Proxmox entries, including entries in /etc/apt/sources.list, to avoid duplicate targets. It also updates an existing Ceph repository to Ceph Squid for Trixie, installs the CPU microcode package for the host, and refreshes the apt cache.

The operator must still run apt policy, pve8to9 --full, and apt dist-upgrade. The playbook does not run apt modernize-sources. That optional post-upgrade command is unavailable on Debian Bookworm with PVE 8 apt. Set proxmox_pve9_write_debian_deb822_sources=true to rewrite the Debian sources as deb822.

Proxmox host baseline

playbooks/proxmox-host-baseline.yml holds the host settings that every Proxmox node shares. Each part has a tag, so one part can run alone.

Tag What it sets
zfs-arc zfs_arc_max in /etc/modprobe.d/zfs.conf and in the running kernel. A change rebuilds the initramfs.
trim org.debian:periodic-trim=enable on the pools in proxmox_host_baseline_zfs_periodic_trim_pools, and fstrim.timer.
stale-units Disables the units in proxmox_host_baseline_disabled_units.
rsyslog-forwarding Removes /etc/rsyslog.d/remote-logging.conf, which forwarded to a listener that no longer exists. rsyslog stays installed.
journald /etc/systemd/journald.conf.d/10-retention.conf.
hosts A marked block in /etc/hosts with the names in proxmox_host_baseline_static_hosts.
vzdump The node default for backup fleecing in /etc/vzdump.conf, on the storage in proxmox_host_baseline_vzdump_fleecing_storage.

Per-node values are in inventory/host_vars/<node>.yml. Values shared by all nodes are in inventory/group_vars/proxmox_hosts.yml.

Debian's monthly ZFS trim job trims a pool by itself only when every disk in it is NVMe. List a pool with SATA SSDs in proxmox_host_baseline_zfs_periodic_trim_pools. The job skips a pool that is not ONLINE.

The journal keeps up to 4 GiB on every node, with no age limit. The file limit is 1000 because journald's default of 100 files ended the history on a ZFS root at about 2 GiB, before the size limit did.

The static names are the ones Proxmox storage definitions use. Cluster DNS is a pod on the cluster these nodes host, so after a full power-off the nodes need the names before DNS is up. proxmox-ntp.yml adds the gateway as a time server by address for the same reason.

Review a node before you change it:

ansible-playbook playbooks/proxmox-host-baseline.yml \
  -e target_hosts=pve3 \
  --check --diff

Check mode shows the two command tasks, the running zfs_arc_max and the initramfs rebuild, as skipped. Run with -v to see whether a skip came from check mode or from a value that already matches.

To point every node at the same Ceph repository without running the rest of the PVE 9 preparation, use the ceph-repo tag:

ansible-playbook playbooks/proxmox-pve9-prereqs.yml --tags ceph-repo --check --diff

Proxmox CPU governor

Ansible does not manage the CPU governor. Root's crontab on pve, pve2, pve3 and pve4 has a hand-added @reboot line that sets powersave a minute after boot.

On the three Intel nodes, intel_pstate still scales up to turbo under powersave. pve uses acpi-cpufreq, where powersave holds the Ryzen 7 2700 at its lowest step, 1.55 GHz. The owner chose to keep that after a measurement on 23 and 24 November 2026, which switched pve between powersave and schedutil every hour for 35 hours:

powersave schedutil
Rack power, mean 453 W 475 W
CPU package, mean 18 W 32 W
CPU temperature, max 48 °C 70 °C
CPU pressure, some 3.1 % 1.3 %
Load average 7.7 4.7

schedutil cost about 22 W at the rack, which is 0.5 kWh a day, and cut CPU pressure by more than half. The extra power and heat were not worth it for this load. If the load on pve grows, measure again before changing the governor.

Proxmox network contract

All nodes provide the same guest-facing bridges, even though their physical NIC names differ.

Bridge Purpose
vmbr0 pfSense WAN, backed by the node-specific WAN NIC
vmbr2 Native LAN and Proxmox management, backed by the node-specific trunk NIC
vmbr20 VLAN 20 as a dedicated bridge
vmbr30 VLAN 30 as a dedicated bridge
vmbr99 VLAN 99 as a dedicated bridge
vmbr1 Optional auxiliary physical network on nodes that have a third mapped NIC

VMs and containers attach directly to their network bridge. A VLAN 20 guest uses bridge=vmbr20 without a Proxmox VLAN tag. pfSense uses one NIC on each routed bridge, matching VM 103 on pve2. Proxmox SDN packages remain installed, but the cluster has no SDN zones or VNets that duplicate these physical bridges.

Physical interface mappings and management addresses are in inventory/host_vars/<node>.yml. To review a node without changing it, run:

ansible-playbook playbooks/proxmox-network.yml \
  -e target_hosts=pve2 \
  --check --diff

After you review the diff and confirm console access, write one node's persistent configuration:

ansible-playbook playbooks/proxmox-network.yml \
  -e target_hosts=pve2 \
  -e proxmox_network_confirm=true \
  --diff

The playbook checks that the mapped NICs exist and that ifupdown2 can parse the generated file. It does not reload networking. Run ifreload -a from the node's console during a maintenance window. Verify pfSense and management connectivity before continuing with the next node.

To create a DNS record, run:

DNS_UPDATE_KEY_SECRET=... ansible-playbook playbooks/k8s-dns-record.yml \
  -e name=app \
  -e ip=192.168.1.50

Where to change things

Need Edit
Add, remove or regroup hosts inventory/hosts.yml
Change group connection settings inventory/group_vars/<group>.yml
Change a playbook target hosts: in playbooks/*.yml
Change role defaults roles/*/defaults/main.yml
Change role behavior roles/*/tasks/main.yml

docs/platform/ansible.md