Proxmox Cleanup & Maintenance Rules
Cleanup Completeness Requirement
- When ANY role deploys a file to the Proxmox host, ALWAYS add it to the removal list in BOTH cleanup playbooks (
molecule/default/cleanup.ymlANDplaybooks/cleanup.yml).
Current Ansible-Managed Files
- Current ansible-managed files that must be cleaned:
/etc/network/interfaces.d/ansible-bridges.conf(bridge config, may be modified toinet dhcp)/etc/network/interfaces.d/ansible-proxmox-lan.conf(legacy LAN management IP, superseded)/etc/network/interfaces.d/ansible-temp-lan.conf(test workaround, cleaned up)/etc/modprobe.d/blacklist-wifi.conf(WiFi driver blacklist)/etc/modprobe.d/vfio-pci.conf(PCI passthrough config)/etc/ansible/facts.d/vm_builds.fact(deploy stamp tracking)/etc/apt/sources.list.d/pve-no-subscription.sources(added byproxmox_igpu)/tmp/openwrt-router-*.img*(left behind if build fails mid-upload)/var/lib/vz/template/cache/debian-*.tar.zst(LXC templates)- Enterprise repos: restore
pve-enterprise.sources.disabled→.sourcesandceph.sources.disabled→.sources
Local State Files Cleanup
Local state files that must be cleaned (via
delegate_to: localhost):.state/addresses.json(cached host IPs)
Previous bug:
ansible-proxmox-lan.confwas deployed but not cleaned up, leaving stale LAN management IPs across test runs.
Test Machine Protocol
- Before running destructive operations (cleanup, VM destroy):
- Confirm the target is the test machine (check
PROXMOX_HOSTenv var) - Verify a backup exists (check for
manifest.jsonin backup dir) - Use the
cleanup.shwrapper which enforces env file sourcing
- Confirm the target is the test machine (check
PCI Device Cleanup Requirement
Devices bound to
vfio-pcido NOT auto-revert when the VM is destroyed. Without cleanup, the next run can't detect WiFi hardware.Required PCI cleanup sequence:
# 1. Unbind all vfio-pci devices for dev in /sys/bus/pci/drivers/vfio-pci/0000:*/; do addr=$(basename "$dev") echo "$addr" > /sys/bus/pci/drivers/vfio-pci/unbind done # 2. Remove blacklist and vfio config files rm -f /etc/modprobe.d/blacklist-wifi.conf /etc/modprobe.d/vfio-pci.conf # 3. Rebind WiFi via sysfs (NEVER modprobe -r) # Use tasks/sysfs_wifi_rebind.yml or inline: for phy in /sys/class/ieee80211/phy*; do PCI=$(basename $(readlink -f "$phy/device")) DRV=$(basename $(readlink -f "$phy/device/driver")) echo "$PCI" > /sys/bus/pci/drivers/$DRV/unbind echo "" > /sys/bus/pci/devices/$PCI/driver_override done # 4. Rescan PCI bus + explicit bind echo 1 > /sys/bus/pci/rescan sleep 1 echo "$PCI" > /sys/bus/pci/drivers/$DRV/bindAll steps are required. The explicit bind (step 4) is critical --
echo 1 > /sys/bus/pci/rescanalone is insufficient because the kernel won't auto-bind drivers that were explicitly unbound.WiFi module unload (
modprobe -r iwlwifi/iwlmvm) is BANNED on ALL hardware. On AMD APUs (Raven Ridge), the NBIO handles ALL PCIe, USB, and SATA on a shared die — a WiFi module unload triggers a PCIe reset that kills USB ethernet hours later. Use sysfs unbind + PCI rescan + explicit bind instead (tasks/sysfs_wifi_rebind.yml). This pattern is universally safe on Intel and AMD, with no hardware-specific branching.
GPU Driver Cleanup — Separate from WiFi
GPU driver cleanup (i915/amdgpu) is DIFFERENT from WiFi cleanup. GPU
modprobe -r amdgpuon a single-GPU AMD host causes a kernel panic (sole framebuffer removal).NEVER run
modprobe -r amdgpuormodprobe -r i915in broad-scope plays (hosts: proxmox*). For E2E cleanup, PCI bus rescan after vfio-pci unbind is sufficient — skip GPU driver unload.ONLY run GPU driver unload in per-feature cleanup (e.g., sunshine-vm, gaming-rollback) gated on
lspci | grep -c 'VGA compatible controller'>= 2.tests/test_host_safety.pyis a static linter that catchesmodprobe -r amdgpu/i915in broad-scope plays without VGA guards. Runpytest tests/to catch this at dev time.Previous bug: E2E cleanup ran
modprobe -r amdgpuon ALL hosts includingai(single AMD GPU, USB ethernet). Kernel panicked, host crashed. Required physical power-on 3000 miles away.
Host Recoverability
Every host MUST declare
wol_capable(true/false) ininventory/host_vars/. Cleanup MUST NOT run operations that could crash hosts withwol_capable: false.Non-WoL hosts (USB ethernet — e.g.,
ai) cannot be recovered remotely. A kernel panic or shutdown is a production-breaking incident requiring physical access.tests/test_wol.pyenforces WoL exclusion.tests/test_host_safety.pyenforces GPU safety. Both run as part ofpytest tests/.