generated from GamingChaos/ansible-repository-template
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
889cc120fe | ||
|
|
cd12d1fa75 | ||
|
|
1ceab1d0ec | ||
|
|
bbfac7a857 | ||
|
|
de010da859 | ||
|
|
85317a0e2a |
@@ -0,0 +1,51 @@
|
|||||||
|
# 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.
|
||||||
@@ -2,3 +2,7 @@
|
|||||||
proxmox_api_host: rimeru.stuyckv.local
|
proxmox_api_host: rimeru.stuyckv.local
|
||||||
proxmox_api_user: ansible@pve
|
proxmox_api_user: ansible@pve
|
||||||
proxmox_api_token_id: ansible
|
proxmox_api_token_id: ansible
|
||||||
|
|
||||||
|
checkmk_api_url: https://checkmk.stuyckv.com/
|
||||||
|
checkmk_api_site: local
|
||||||
|
checkmk_api_user: ansible
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
$ANSIBLE_VAULT;1.1;AES256
|
||||||
|
63643461333732333933306361633239656336663835393137353361353331363065303939643639
|
||||||
|
6162643138613434653034626466613731663661353161350a656634643739636231363330613637
|
||||||
|
63343936303665643532363932396239373135643766383563636532393762313837393364393561
|
||||||
|
6630393133656337650a313465663663373131373561613333313366386237366137663563383231
|
||||||
|
64303065343330643136373437306534336238633665356462653439306432663063366639333330
|
||||||
|
34353430623463303863326133303032646161376435643133353866626534643433373538336265
|
||||||
|
37626264663935373838666233383039323135383837633131613435373732616433306564313466
|
||||||
|
62653733663063616362323937376431386332326533633132363430666531333166616365306332
|
||||||
|
64336139386663653861346331616530346431656232343539636262643936386436
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
$ANSIBLE_VAULT;1.1;AES256
|
|
||||||
66393831316666346565393032333961373365346633643730386661616332356431653331396334
|
|
||||||
3633373066646165636639646462376338366665376561650a643530306339666436323130383737
|
|
||||||
36373532623435336466386433326664356537326137363537343133323739343732383565346336
|
|
||||||
6630636236363261610a646336613436323462663339313364393833653539653238666437623261
|
|
||||||
65383864346165623730363136353838396131643962393134366362393266356365396231633064
|
|
||||||
65366631653437626666343465383338383637373139353130623961316662353431313037303834
|
|
||||||
36356131323233613461333163303537306635343065663435333961376264316235643335323661
|
|
||||||
36336331336537343432
|
|
||||||
@@ -3,6 +3,8 @@ shion.stuyckv.local
|
|||||||
charybdis.stuyckv.local
|
charybdis.stuyckv.local
|
||||||
ramiris.stuyckv.local
|
ramiris.stuyckv.local
|
||||||
millim.stuyckv.local
|
millim.stuyckv.local
|
||||||
|
shuna.stuyckv.local
|
||||||
|
diablo.stuyckv.local
|
||||||
guy.stuyckv.local
|
guy.stuyckv.local
|
||||||
claymen.stuyckv.local
|
claymen.stuyckv.local
|
||||||
leon.stuyckv.local
|
leon.stuyckv.local
|
||||||
@@ -11,6 +13,7 @@ leon.stuyckv.local
|
|||||||
charybdis.stuyckv.local
|
charybdis.stuyckv.local
|
||||||
ramiris.stuyckv.local
|
ramiris.stuyckv.local
|
||||||
millim.stuyckv.local
|
millim.stuyckv.local
|
||||||
|
diablo.stuyckv.local
|
||||||
|
|
||||||
[kubernetes]
|
[kubernetes]
|
||||||
guy.stuyckv.local
|
guy.stuyckv.local
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ shion.stuyckv.local
|
|||||||
charybdis.stuyckv.local
|
charybdis.stuyckv.local
|
||||||
ramiris.stuyckv.local
|
ramiris.stuyckv.local
|
||||||
millim.stuyckv.local
|
millim.stuyckv.local
|
||||||
|
shuna.stuyckv.local
|
||||||
|
diablo.stuyckv.local
|
||||||
guy.stuyckv.local
|
guy.stuyckv.local
|
||||||
claymen.stuyckv.local
|
claymen.stuyckv.local
|
||||||
leon.stuyckv.local
|
leon.stuyckv.local
|
||||||
|
|||||||
@@ -1,10 +1,23 @@
|
|||||||
---
|
---
|
||||||
# source: https://www.jeffgeerling.com/blog/2022/ansible-playbook-upgrade-ubuntudebian-servers-and-reboot-if-needed
|
# source: https://www.jeffgeerling.com/blog/2022/ansible-playbook-upgrade-ubuntudebian-servers-and-reboot-if-needed
|
||||||
- hosts: ubuntu
|
- hosts: ubuntu
|
||||||
gather_facts: yes
|
gather_facts: true
|
||||||
become: yes
|
become: true
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Create Downtime
|
||||||
|
become: false
|
||||||
|
delegate_to: localhost
|
||||||
|
checkmk.general.downtime:
|
||||||
|
server_url: "{{ checkmk_api_url }}"
|
||||||
|
site: "{{ checkmk_api_site }}"
|
||||||
|
api_user: "{{ checkmk_api_user }}"
|
||||||
|
api_secret: "{{ checkmk_api_secret }}"
|
||||||
|
host_name: "{{ inventory_hostname }}"
|
||||||
|
comment: "created by update-debian playbook"
|
||||||
|
end_after:
|
||||||
|
hours: 1
|
||||||
|
|
||||||
- name: Perform a dist-upgrade.
|
- name: Perform a dist-upgrade.
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
upgrade: dist
|
upgrade: dist
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
---
|
---
|
||||||
|
# ansible-galaxy install -r requirements.yml
|
||||||
|
|
||||||
collections:
|
collections:
|
||||||
- name: community.proxmox
|
- name: community.proxmox
|
||||||
version: "1.6.0"
|
version: "1.6.0"
|
||||||
|
- name: checkmk.general
|
||||||
|
version: "8.6.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user