Skip to content

feat(aap_cleanup): add role to remove AAP artifacts created by aap_seed - #123

Merged
tech2734 merged 4 commits into
redhat-cop:v2from
tech2734:feat/aap-cleanup
Nov 4, 2026
Merged

tech2734 merged 4 commits into
redhat-cop:v2from
tech2734:feat/aap-cleanup

Conversation

@tech2734

@tech2734 tech2734 commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

Adds a new aap_cleanup role and vmf_cleanup_aap.yml playbook that removes all AAP objects created by aap_seed.

What it does

Removes objects in dependency order:

  1. Job templates
  2. Credentials (discovered from inventory groups or explicit names)
  3. Credential types
  4. Project
  5. Execution environment
  6. Hosts
  7. Inventory
  8. Organization

Toggles

  • Master switch — aap_cleanup_all: true (default) removes everything
  • Individual toggles — set aap_cleanup_all: false and enable per-category toggles (aap_cleanup_templates, aap_cleanup_credentials, etc.)

Files added

  • roles/aap_cleanup/defaults/main.yml — variables with cascade from inventory
  • roles/aap_cleanup/tasks/main.yml — removal tasks using module_defaults
  • roles/aap_cleanup/meta/argument_specs.yml — full argument specs
  • roles/aap_cleanup/meta/main.yml — galaxy metadata
  • roles/aap_cleanup/README.md — auto-generated docs
  • playbooks/vmf_cleanup_aap.yml — playbook (uses import_role, consistent with other playbooks)

Testing

  • Tested seed → cleanup round-trip on homelab AAP 2.5
  • All objects removed cleanly (ok=11, changed=8, failed=0)

@tech2734
tech2734 requested a review from sabre1041 as a code owner October 26, 2026 19:20
@tech2734
tech2734 deployed to external-ci October 26, 2026 19:20 — with GitHub Actions Active
Adds the aap_cleanup role and vmf_cleanup_aap.yml playbook to tear down
AAP Configuration-as-Code objects seeded by aap_seed — job templates,
credentials, credential types, projects, execution environments, hosts,
inventories, and the organization.

Features:
- Master switch (aap_cleanup_all, default: true) removes everything
- Individual toggles for selective removal when aap_cleanup_all is false
- Object name lists can be narrowed to target specific items
- Removal order respects dependencies (templates first, org last)
- Credential names auto-discovered from inventory groups
- Organization deleted via gateway API (AAP 2.5 compatible)

Tested: full seed → cleanup round-trip against AAP 2.5 homelab.
Co-authored-by: Cursor <cursoragent@cursor.com>
…ection

Replace individual ansible.controller.* module calls with the same
infra.aap_configuration dispatch pattern that aap_seed uses, but in
reverse (state: absent).

Key changes:
- Discover resources via AAP API (scoped to target org)
- Build state:absent lists and dispatch through CaC collection
- Add dry-run mode (aap_cleanup_dry_run)
- Remove hardcoded object name lists (dynamic discovery)
- Add _build_absent_resources.yml reusable include task
- Hosts scoped by inventory__organization for safety
- Organization removal filtered by name to avoid touching Default org
- Simplify defaults and argument specs to match new approach

Co-authored-by: Cursor <cursoragent@cursor.com>
@tech2734
tech2734 deployed to external-ci October 29, 2026 01:42 — with GitHub Actions Active

@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.

One requested change and one question

Comment thread roles/aap_cleanup/meta/main.yml Resolved
Comment thread roles/aap_cleanup/README.md Resolved
- Author: Red Hat CoP → Red Hat
- License: GPL-3.0-or-later → GPL-3.0-only
- Remove platforms and galaxy_tags (match collection convention)

Co-authored-by: Cursor <cursoragent@cursor.com>
@tech2734
tech2734 deployed to external-ci October 29, 2026 20:00 — with GitHub Actions Active
@sabre1041

Copy link
Copy Markdown
Contributor

@tech2734 Thanks for updating the galaxy metadata file. Still interested in your thoughts on the aap_cleanup_all logic being explicit vs implicit. Otherwise, we can look to merge this in

@tech2734

tech2734 commented Nov 2, 2026

Copy link
Copy Markdown
Author

@sabre1041 I am still on the fence regarding the implicit vs. explicit. I see pros/cons with either. Maybe we can get others' opinions on this.

Require an explicit opt-in — either aap_cleanup_all=true or at least one
individual toggle — so selective cleanup only removes chosen categories.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tech2734
tech2734 deployed to external-ci November 2, 2026 21:28 — with GitHub Actions Active

@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

@tech2734
tech2734 merged commit 8ff63c4 into redhat-cop:v2 Nov 4, 2026
22 checks passed

This branch was successfully deployed

1 active deployment
external-ci — 8d7e1c5f Deployed Nov 2, 2026 by tech2734 via external-approval #812
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.

2 participants