Nik Afiq 5a00f5767b fix: Ansible cleanup -- merge dual config, pin collections, align K3s version, fix bugs
Stage 4 of REFACTOR_PLAN.md.

- Merge ansible/ansible.cfg into root ansible.cfg (single source of truth);
  the dual-config setup silently broke documented commands and lost
  host_key_checking=False when run from the ansible/ directory.
- Add ansible/requirements.yml pinning community.general, ansible.posix,
  community.docker -- previously undocumented deps of the glances/watch-party
  roles that would fail a fresh bootstrap.
- Align K3s version to v1.32.4+k3s1 across roles/k3s-server, roles/k3s-agent,
  and host_vars/gpu-node.yaml defaults (was skewed: .2 vs .4). This only
  changes what a *future* provision installs -- minisforum/debian are still
  live on v1.32.2+k3s1 until separately upgraded.
- Fix kubeconfig fetch/replace path mismatch in k3s-server role: the `fetch`
  task (flat: true) writes to ~/.kube/config, but `replace` was targeting a
  /tmp/k3s-minisforum.yaml nothing creates -- would break a fresh rebuild.
- gitea-runner: only remove /run/docker.sock when it's actually a directory
  (task name implied a check that wasn't there); tighten registration-token
  systemd unit from 0644 to 0600.
- nvidia: stop unconditionally reporting `changed` (and restarting Docker)
  on every run for an idempotent runtime-configure command.
- Gate the K3s join-token debug print and WireGuard client-config/QR display
  behind opt-in vars (k3s_show_token, wireguard_show_client_configs), default
  off -- both were printing real secrets to console on every run.
- Parameterize the docker role for Debian and Ubuntu; homeassistant now
  depends on it (meta/main.yaml) instead of duplicating a Debian-only Docker
  install inline.
- FQCN cleanup across wireguard, homeassistant, and ollama roles/handlers
  (bare module names -> ansible.builtin.*/community.general.*/ansible.posix.*),
  plus a few ansible-lint name-casing/idiom fixes. Handler renames verified
  against their `notify:` call sites so notifications still fire.
- Update ansible/README.md and root README.md: add gpu-node/gpu_workstation
  (4th host, previously undocumented), docker/nvidia roles, setup-gpu-node.yaml,
  homeassistant.yaml, requirements.yml install step; correct the "Legacy"
  homeassistant label (it's the only thing serving ha.home.arpa); correct the
  Gitea ingress/backup-storage doc-drift; flag the Grafana/Loki static-PV
  binding drift discovered via live cluster check.

Verified: all playbooks pass `ansible-playbook --syntax-check`, yamllint clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-23 18:15:12 +09:00

190 lines
4.7 KiB
YAML

---
- name: Install WireGuard and tools
ansible.builtin.apt:
name:
- wireguard
- wireguard-tools
- qrencode
state: present
update_cache: true
- name: Allow WireGuard port through UFW
community.general.ufw:
rule: allow
port: "51820"
proto: udp
- name: Enable IP forwarding
ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: "1"
sysctl_set: true
state: present
reload: true
- name: Create WireGuard config directory
ansible.builtin.file:
path: /etc/wireguard
state: directory
mode: "0700"
owner: root
group: root
# --- Server keypair ---
- name: Check if server private key exists
ansible.builtin.stat:
path: /etc/wireguard/server.key
register: server_key_stat
- name: Generate server private key
ansible.builtin.shell: wg genkey > /etc/wireguard/server.key
when: not server_key_stat.stat.exists
- name: Set permissions on server private key
ansible.builtin.file:
path: /etc/wireguard/server.key
mode: "0600"
owner: root
group: root
- name: Read server private key
ansible.builtin.slurp:
src: /etc/wireguard/server.key
register: server_private_key
- name: Derive server public key
ansible.builtin.shell: wg pubkey < /etc/wireguard/server.key
register: server_public_key
changed_when: false
# --- Phone keypair ---
- name: Check if phone private key exists
ansible.builtin.stat:
path: /etc/wireguard/phone.key
register: phone_key_stat
- name: Generate phone private key
ansible.builtin.shell: wg genkey > /etc/wireguard/phone.key
when: not phone_key_stat.stat.exists
- name: Set permissions on phone private key
ansible.builtin.file:
path: /etc/wireguard/phone.key
mode: "0600"
owner: root
group: root
- name: Read phone private key
ansible.builtin.slurp:
src: /etc/wireguard/phone.key
register: phone_private_key
- name: Derive phone public key
ansible.builtin.shell: wg pubkey < /etc/wireguard/phone.key
register: phone_public_key
changed_when: false
# --- Mac keypair ---
- name: Check if mac private key exists
ansible.builtin.stat:
path: /etc/wireguard/mac.key
register: mac_key_stat
- name: Generate mac private key
ansible.builtin.shell: wg genkey > /etc/wireguard/mac.key
when: not mac_key_stat.stat.exists
- name: Set permissions on mac private key
ansible.builtin.file:
path: /etc/wireguard/mac.key
mode: "0600"
owner: root
group: root
- name: Read mac private key
ansible.builtin.slurp:
src: /etc/wireguard/mac.key
register: mac_private_key
- name: Derive mac public key
ansible.builtin.shell: wg pubkey < /etc/wireguard/mac.key
register: mac_public_key
changed_when: false
# --- Server config ---
- name: Write wg0.conf
ansible.builtin.template:
src: wg0.conf.j2
dest: /etc/wireguard/wg0.conf
mode: "0600"
owner: root
group: root
notify: Restart wg0
# --- Service ---
- name: Enable and start wg-quick@wg0
ansible.builtin.systemd:
name: wg-quick@wg0
enabled: true
state: started
# --- Phone client config + QR ---
- name: Write phone client config
ansible.builtin.copy:
dest: /etc/wireguard/phone-client.conf
mode: "0600"
owner: root
group: root
content: |
[Interface]
PrivateKey = {{ phone_private_key.content | b64decode | trim }}
Address = 10.10.0.2/32
DNS = 192.168.7.77
[Peer]
PublicKey = {{ server_public_key.stdout }}
Endpoint = {{ wireguard_endpoint }}:51820
AllowedIPs = 192.168.7.0/24, 10.10.0.0/24
PersistentKeepalive = 25
# --- Mac client config ---
- name: Write mac client config
ansible.builtin.copy:
dest: /etc/wireguard/mac-client.conf
mode: "0600"
owner: root
group: root
content: |
[Interface]
PrivateKey = {{ mac_private_key.content | b64decode | trim }}
Address = 10.10.0.3/32
DNS = 192.168.7.77
[Peer]
PublicKey = {{ server_public_key.stdout }}
Endpoint = {{ wireguard_endpoint }}:51820
AllowedIPs = 192.168.7.0/24, 10.10.0.0/24
PersistentKeepalive = 25
- name: Display mac client config
ansible.builtin.shell: cat /etc/wireguard/mac-client.conf
register: mac_conf
changed_when: false
when: wireguard_show_client_configs | default(false)
- name: Show mac client config
ansible.builtin.debug:
msg: "{{ mac_conf.stdout_lines }}"
when: wireguard_show_client_configs | default(false)
- name: Generate QR code for phone
ansible.builtin.shell: qrencode -t ansiutf8 < /etc/wireguard/phone-client.conf
register: phone_qr
changed_when: false
when: wireguard_show_client_configs | default(false)
- name: Display phone QR code
ansible.builtin.debug:
msg: "{{ phone_qr.stdout_lines }}"
when: wireguard_show_client_configs | default(false)