Dynamic Group Reconstruction for Rollback
Group Reconstruction Requirement
Rollback plays targeting dynamic groups (e.g.,
openwrt) MUST be preceded by a group reconstruction play incleanup.yml. The dynamic group is ephemeral —add_hoststate does not persist acrossansible-playbookinvocations.Without reconstruction, rollback plays have no hosts to target.
Group Reconstruction Implementation
ALWAYS add a reconstruction play at the top of
cleanup.yml, tagged with ALL rollback tags so it runs whenever any rollback is invoked:# In playbooks/cleanup.yml — BEFORE any rollback plays - name: Reconstruct openwrt dynamic group hosts: router_nodes tags: [openwrt-security-rollback, openwrt-vlans-rollback, openwrt-dns-rollback, openwrt-mesh-rollback] gather_facts: true tasks: - name: Include group reconstruction ansible.builtin.include_tasks: tasks/reconstruct_openwrt_group.yml
Reconstruction Task File Pattern
Extract reconstruction logic into a reusable task file (
tasks/reconstruct_openwrt_group.yml) consumed by converge, verify, and cleanup entry points.The reconstruction task file:
- Verifies VM 100 is running via
qm status - Detects the OpenWrt LAN IP from Proxmox bridge state
- Detects the current SSH auth method (key vs. password) by checking
OPENWRT_SSH_PRIVATE_KEYandansible_local.vm_builds.plays - Registers the host via
add_hostwith the correct SSH arguments
- Verifies VM 100 is running via
Auth Method Detection
The group reconstruction play MUST detect the current auth method (key vs. password) by checking for
OPENWRT_SSH_PRIVATE_KEYenv var anddeploy_stampstate.After a security hardening rollback, the auth method reverts to password — reconstruction must handle both.
Version-Aware Convergence Integration
When
project_versioningroup_vars/all.ymladvances:deploy_stampcompares the new version againstansible_local.vm_builds.project_version- Feature plays check their own play entry version against current
- If the versions match, skip expensive operations (package installs, downloads)
- If the versions differ, re-apply the feature (idempotent convergence)
This is the migration path: bump
project_version, update the feature play, run converge. The play detects the version mismatch and re-applies. No separate migration playbook needed.