Skip to content

feat: add cleanup playbooks for migration test environments#51

Merged
sabre1041 merged 6 commits into
mainfrom
feat/cleanup-playbooks
Jul 9, 2026
Merged

feat: add cleanup playbooks for migration test environments#51
sabre1041 merged 6 commits into
mainfrom
feat/cleanup-playbooks

Conversation

@stevefulme1

Copy link
Copy Markdown
Contributor

Summary

  • Add aap_cleanup and ocp_cleanup roles with idempotent cleanup automation for migration test environments
  • Add 4 cleanup playbooks: Bootstrap AAP, Migration AAP, OCP artifacts, and an aggregator (cleanup_all.yml) for CI integration
  • Add molecule test scenarios and integration test targets

What this solves

MFG-382 — The collection creates resources across 3 systems (Bootstrap AAP, Migration AAP, OpenShift cluster) during migration testing but has zero teardown automation. Tests leave stale resources with no clean slate between cycles.

New roles

aap_cleanup

  • Discovers AAP resources via controller API (decoupled from aap_seed templates)
  • Removes in reverse dependency order: workflows → templates → credentials → projects → inventories → EEs → credential types → orgs
  • Supports dry-run mode (aap_cleanup_dry_run: true)
  • Parameterized provider filtering (cleanup_providers: [vmware, ovirt])
  • Optional job history purge (migration instance only)

ocp_cleanup

  • Removes MTV CRDs (Migrations → Plans → Maps → Providers) with dependency-aware ordering
  • Removes provider/VDDK secrets
  • Optional: migrated VMs + PVCs, target namespaces, full operator teardown
  • Query-then-delete pattern handles already-absent resources gracefully
  • Supports dry-run mode (ocp_cleanup_dry_run: true)

New playbooks

Playbook Target Notes
cleanup_bootstrap_aap.yml Bootstrap AAP No job history purge
cleanup_migration_aap.yml Migration AAP Job history purge enabled
cleanup_ocp_migration_artifacts.yml OpenShift cluster MTV CRDs + secrets
cleanup_all.yml All 3 systems Aggregator with ignore_errors for CI

CI pipeline integration

A separate PR will be needed in openshift_virtualization_migration_ci to add a _cleanup-stage.yml workflow that runs cleanup_all.yml as a post-test step (with if: always()). Draft spec available.

Test plan

  • yamllint passes on all new files (verified locally)
  • ansible-lint passes on new roles and playbooks
  • Molecule scenarios auto-discovered by tox
  • Dry-run mode on both roles reports resources without deleting
  • Idempotent: second run reports 0 changes
  • Cleanup against populated test environment returns to clean state
  • cleanup_all.yml continues execution when one sub-playbook fails

Jira

Resolves MFG-382

Related tasks:

  • MFG-384 — Bootstrap AAP cleanup playbook
  • MFG-386 — Migration AAP cleanup playbook
  • MFG-388 — OCP artifact cleanup playbook
  • MFG-389 — Pipeline integration (separate CI repo PR)

Add idempotent Ansible roles and playbooks to reset Bootstrap AAP,
Migration AAP, and OpenShift cluster artifacts after migration testing.

New roles:
- aap_cleanup: discovers and removes AAP resources via controller API,
  supports dry-run mode and parameterized provider filtering
- ocp_cleanup: removes MTV CRDs, secrets, migrated VMs/PVCs, and
  optionally tears down operators with dependency-aware deletion order

New playbooks:
- cleanup_bootstrap_aap.yml
- cleanup_migration_aap.yml
- cleanup_ocp_migration_artifacts.yml
- cleanup_all.yml (aggregator for CI pipeline integration)

Includes molecule test scenarios and integration test targets.

Resolves: MFG-382
@stevefulme1 stevefulme1 requested a review from sabre1041 as a code owner July 1, 2026 16:09

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible-lint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

- Add `_filename | ` prefix to all task names in included task files
  (ansible-lint name[prefix] rule)
- Fix cleanup_all.yml: replace invalid `ignore_errors` on
  `import_playbook` with block/rescue pattern per playbook schema
- Add document end markers `...` to molecule files
- Regenerate role READMEs via docsible (pre-commit hook requirement)
Comment thread roles/aap_cleanup/tasks/_build_absent_resources.yml Fixed
Comment thread roles/aap_cleanup/tasks/_build_absent_resources.yml Fixed
Comment thread roles/aap_cleanup/tasks/_build_absent_resources.yml Fixed
Comment thread roles/aap_cleanup/tasks/_build_absent_resources.yml Fixed
Comment thread roles/ocp_cleanup/tasks/_cleanup_mtv_crds.yml Fixed
Comment thread roles/ocp_cleanup/tasks/_cleanup_operator_item.yml Fixed
Comment thread roles/ocp_cleanup/tasks/_cleanup_operator_item.yml Fixed
Comment thread roles/ocp_cleanup/tasks/_cleanup_operator_item.yml Fixed
Comment thread roles/ocp_cleanup/tasks/_cleanup_operator_item.yml Fixed
Comment thread roles/aap_cleanup/tasks/_build_absent_resources.yml Fixed
- Move Jinja templates to end of task names (name[template] rule)
- Replace all ignore_errors with failed_when: false (ignore-errors rule)
- Add noqa for controller_dependency_check var required by dispatch
- Remove duplicate License heading (MD024 — docsible generates its own)
- Regenerate docsible documentation
- Default validate_certs to true when env lookup returns empty string
  (prevents 'not a valid boolean' error in uri module)
- Rewrite integration tests to validate role defaults loading and
  variable assertions instead of calling roles that need live AAP/OCP
Integration tests run in molecule temp directories where relative paths
to role defaults don't resolve. Switch to ansible-doc role introspection
which works against the installed collection path.

@sabre1041 sabre1041 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments from the initial review. Lots of good stuff here @stevefulme1

Comment thread playbooks/cleanup_bootstrap_aap.yml Outdated
Comment thread playbooks/cleanup_all.yml Outdated
Comment thread roles/aap_cleanup/tasks/main.yml
Comment thread roles/aap_cleanup/tasks/main.yml
Remove bootstrap cleanup playbook and play — bootstrap concept no longer
exists. Add _aap_cleanup_use_org_filter: false to hosts and credential_types
tasks where the AAP API does not support organization-scoped queries.

@sabre1041 sabre1041 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sabre1041 sabre1041 merged commit c23dd01 into main Jul 9, 2026
26 checks passed
@sabre1041 sabre1041 deleted the feat/cleanup-playbooks branch July 9, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants