Files
ansible-homelab/CLAUDE.md
T

4.6 KiB
Raw Blame History

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

What this is

Ansible playbooks for a homelab: Ubuntu VMs on a Proxmox host (rimeru), a TrueNAS box (veldora), and a Checkmk monitoring server (shion). There are no roles and no ansible.cfg. Everything is a standalone playbook in playbooks/. README.md is the human-facing overview: setup, the playbook table, and the steps for adding a host.

Setup and commands

./init.sh                      # creates ./venv, installs requirements.txt (proxmoxer, requests) and Galaxy collections
ansible-galaxy collection install -r requirements.yml   # collections only: community.proxmox, checkmk.general

Ansible itself is not in requirements.txt. It must already be installed on the machine.

Without an ansible.cfg, you always pass the inventory explicitly. Use the directory so both inventory files and group_vars/host_vars get loaded:

ansible-playbook -i inventory/ playbooks/<playbook>.yml --ask-vault-pass
ansible-playbook -i inventory/ playbooks/<playbook>.yml --syntax-check
ansible-playbook -i inventory/ playbooks/<playbook>.yml --check --limit <host>
ansible-vault edit inventory/group_vars/all/vault.yml

The # noqa: annotations in the playbooks are for ansible-lint (ansible-lint playbooks/).

Inventory layout

  • inventory/homelab holds the infrastructure groups: ubuntu (all Ubuntu VMs), docker, kubernetes, proxmox, truenas.
  • inventory/monitoring holds the Checkmk groups: sites (Checkmk servers) and agents (hosts that run the Checkmk agent). When you add a host to the homelab, it usually also goes into agents (see README for the full steps).
  • inventory/group_vars/all/ holds the API connection vars for both Proxmox and Checkmk (servers.yml) plus vault.yml, which is Ansible Vault–encrypted and holds the matching secrets (proxmox_api_token_secret, checkmk_api_secret). They live under all (not sites) so the ubuntu hosts in update-debian.yml can reach the Checkmk API vars too. Secrets go in vault files, not inline in playbooks.
  • inventory/host_vars/<fqdn>.yml for a Checkmk server sets checkmk_sites (the list of OMD site names to manage) and vmid. No playbook reads vmid yet. The snapshot task finds the VM by name instead.

Playbook notes

  • update-checkmk.yml has three plays that share state through a fact:

    1. On all hosts, delegated to localhost, it gets the latest stable Checkmk tag from GitHub with git ls-remote and sets checkmk_version. It targets all on purpose: a set_fact only applies to the hosts in its own play, so sites and agents would lose the fact if the play ran only on localhost (or they'd have to read hostvars['localhost'].checkmk_version).
    2. On sites, it reads the installed version with omd version -b (as the login user, no become) and ends the play for that host (meta: end_host) when it already matches checkmk_version. Otherwise it snapshots the VM through the Proxmox API (delegated to localhost, using inventory_hostname_short as the Proxmox VM name), installs the community-edition .deb, then runs omd stop, backup, update and start for each entry in checkmk_sites.
    3. On agents, it installs the agent .deb from the local Checkmk server (checkmk.stuyckv.com/local), then registers the agent for TLS with cmk-agent-ctl register, using the checkmk_api_* vars. It registers on every run on purpose, because registering again renews the agent certificate. checkmk.general has an agent role but no agent module, so this is done with a plain command.

    Package installs only run when ansible_facts.lsb.id == 'Ubuntu'.

  • update-debian.yml runs against ubuntu. It sets a Checkmk downtime through checkmk.general, then runs dist-upgrade, reboots if needed and autoremoves. Like the Proxmox snapshot, the downtime task is delegated to localhost with become: false.

  • install-kubernetes.yml (untested) prepares the kubernetes group with Docker CE, containerd and kubeadm/kubelet/kubectl pinned to the v1.35 repo. The untracked install-kube.sh is the shell version it was ported from.

Conventions

  • Newer playbooks use FQCN module names (ansible.builtin.*) and the boolean literals true/false (not yes/no). install-kubernetes.yml doesn't follow either yet, and update-debian.yml still has some yes/no.
  • Shell/command tasks set changed_when explicitly.
  • Managed hosts are reached as the ansible user with passwordless sudo, set up by create-ansibleuser.sh. It authorizes an ansible@semaphore key, so the playbooks are also run from Ansible Semaphore.