3.8 KiB
3.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Repository Overview
This is an Ansible infrastructure management repository that manages a mixed environment including network services, monitoring, VPN infrastructure, and web applications. The codebase supports multiple operating systems (Debian, Ubuntu, AlmaLinux) and uses a role-based architecture for modularity.
Note: Flatcar Container Linux VMs are provisioned by OpenTofu and configured via Butane/Ignition — they are NOT managed by Ansible.
Common Commands
Bootstrap New Hosts
# Initial bootstrap (requires password)
make bootstrap-init HOSTNAME=hostname ANSIBLE_HOST=ip_address
# Full bootstrap with network config and reboot
make bootstrap HOSTNAME=hostname ANSIBLE_HOST=ip_address
Run playbooks
# Run main playbook
./run.sh
# Run all plays on specific host
ansible-playbook -l hostname playbook.yml
# Run specific tags
ansible-playbook -t caddy playbook.yml
Development Tasks
# Gather facts from all hosts
ansible -m setup all
# Test changes on specific host
ansible-playbook -l hostname playbook.yml
# Check syntax
ansible-playbook --syntax-check playbook.yml
# Dry run
ansible-playbook --check playbook.yml
Architecture
Playbook Structure
playbook.yml- Main playbook for all configuration (common, firewall, DNS, Caddy, general, monitoring, PostgreSQL, prometheus stack, etc.)bootstrap.yml- Initial host preparationnetbox.yml- Standalone NetBox deployment
Role Organization
Roles follow a standard structure with:
tasks/main.yml- Main task listhandlers/main.yml- Service restart handlerstemplates/- Jinja2 templates for config filesvars/- Role-specific variablesdefaults/- Default variable values
Key Roles
base- Combined base configuration (users, SSH, sudo, packages)general- General system configurations (motd, network, syslog, NFS, K3s)caddy- Web server and reverse proxyfirewall- UFW/firewalld rule managementns- BIND9 nameserver configurationtailscale- Tailscale VPN setupmonitor- Icinga2 monitoring masterprometheus/alertmanager/loki/grafana/node_exporter- Prometheus monitoring stacknetbox- NetBox IPAM/DCIMpgbouncer- PostgreSQL connection poolerlibrenms- LibreNMS network monitoringmailcow- Mailcow email serverdokku- Dokku PaaSaprsc- APRS-IS serveruisp- Ubiquiti UISPsyncthing- Syncthing file sync
Variable Precedence
- Host-specific vars in
host_vars/ - Group vars in
group_vars/ - Role defaults in
roles/*/defaults/ - Base variables in
vars/
Service Dependencies
- SSH configuration managed by base role
- Firewall rules (UFW/firewalld) applied before service configs
- Handlers ensure services restart when configs change
- Tailscale VPN requires
TAILSCALE_AUTHKEY(orTAILSCALE_KEY) environment variable - SSH key path defaults to
~/.ssh/ansible; override viaANSIBLE_SSH_PRIVATE_KEY_FILEenv var
Key Patterns
User Management
- Ansible user (UID 10001) created on all hosts
- SSH keys fetched from GitHub for authentication
- Passwordless sudo configured for automation
Network Services
- DNS resolvers are Flatcar VMs managed via OpenTofu + Butane (see ../tofu/)
- Nameservers configured via ns role
- Caddy serves as reverse proxy for web services
- Tailscale provides VPN connectivity
Configuration Management
- Templates use host-specific variables
- Handlers manage service restarts
- Fact caching improves performance
- Collections required: ansible.posix, community.general, kubernetes.core, community.postgresql, community.proxmox, community.mysql
Memories
Playbook Defaults
- The default ansible playbook is
playbook.yml