Files
ansible-homelab/CLAUDE.md
T
2026-10-27 08:54:30 +01:00

52 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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/`. The README is the generic Ansible best-practices template and doesn't describe this repo.
## Setup and commands
```sh
./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:
```sh
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 the recent commits).
- `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 `localhost`, it gets the latest stable Checkmk tag from GitHub with `git ls-remote` and sets `checkmk_version`. A `set_fact` only applies to the hosts in its own play, so later plays only see the fact if this play covers their hosts too (as `hosts: all` plus `delegate_to: localhost` did) or if they read it as `hostvars['localhost'].checkmk_version`.
2. On `sites`, 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`).
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.