Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ci/playbooks/clean-config-drives-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

# This playbook cleans only config drive ISO files to allow infrastructure reuse.
# It does NOT clean libvirt VMs or other resources - only config drives.
# This is needed when reusing infrastructure to avoid conflicts with existing
# ISO files that might be attached to VMs.

- name: Clean config drives for infrastructure reuse
hosts: "{{ cifmw_target_host | default('localhost') }}"
gather_facts: true
tasks:
- name: Cleanup config_drive workdir
ansible.builtin.include_role:
name: config_drive
tasks_from: cleanup.yml

- name: Remove ISO files from workload directory
when: cifmw_libvirt_manager_basedir is defined
ansible.builtin.find:
paths: "{{ cifmw_libvirt_manager_basedir }}/workload"
patterns: "*.iso"
register: _iso_files
failed_when: false

- name: Delete ISO files from workload directory
when:
- cifmw_libvirt_manager_basedir is defined
- _iso_files.files | default([]) | length > 0
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ _iso_files.files | default([]) }}"
failed_when: false
# Note: This may fail if ISO is attached to a running VM, but that's okay
# The config_drive role will handle the case where ISO doesn't exist
108 changes: 108 additions & 0 deletions cleanup-openstack-for-reuse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
# Copyright Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

# This playbook cleans up OpenStack resources while preserving the OpenShift
# cluster infrastructure for reuse. It removes:
# - All OpenStack CRs (ControlPlane, DataPlane, etc.)
# - Storage resources (PVCs, secrets, ConfigMaps)
# - Optionally: OpenStack API resources (servers, networks, volumes, etc.)
#
# Usage examples:
#
# Basic cleanup (removes OpenStack CRs and storage, keeps cluster):
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml
#
# Dry-run mode (preview what would be deleted):
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
# -e dry_run=true
#
# Skip API resource cleanup (if needed):
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
# -e cleanup_api_resources=false
#
# Selective cleanup using tags:
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
# --tags cleanup_storage,cleanup_crs_direct
#
# Aggressive cleanup (removes everything including namespaces):
# ansible-playbook -i inventory.yml cleanup-openstack-for-reuse.yml \
# -e cleanup_api_resources=true \
# -e cleanup_namespaces=true \
# -e force_remove_finalizers=true

- name: Clean OpenStack deployment for infrastructure reuse
hosts: "{{ target_host | default('localhost') }}"
gather_facts: true
vars:
# Dry-run mode - preview without making changes
cifmw_cleanup_openstack_dry_run: "{{ dry_run | default(false) }}"
# By default, clean OpenStack CRs, storage, and API resources but keep OpenShift cluster
# Set to false to skip OpenStack API resource cleanup
cifmw_cleanup_openstack_delete_api_resources: "{{ cleanup_api_resources | default(true) }}"
# Set to true to delete namespaces (use with caution)
cifmw_cleanup_openstack_delete_namespaces: "{{ cleanup_namespaces | default(false) }}"
# Set to true to force remove finalizers from stuck CRs
cifmw_cleanup_openstack_force_remove_finalizers: "{{ force_remove_finalizers | default(false) }}"
tasks:
- name: Cleanup OpenStack deployment
ansible.builtin.include_role:
name: cleanup_openstack

- name: Verify cleanup succeeded (if not dry-run)
when: not cifmw_cleanup_openstack_dry_run | bool
block:
- name: Verify OpenStackControlPlane CRs are removed
kubernetes.core.k8s_info:
kubeconfig: "{{ _k8s_kubeconfig | default(omit) }}"
api_key: "{{ cifmw_openshift_token | default(omit) }}"
context: "{{ cifmw_openshift_context | default(omit) }}"
api_version: core.openstack.org/v1beta1
kind: OpenStackControlPlane
namespace: "{{ cifmw_kustomize_deploy_namespace | default('openstack') }}"
register: _verify_controlplane
failed_when: false

- name: Verify OpenStackDataPlaneNodeSet CRs are removed
kubernetes.core.k8s_info:
kubeconfig: "{{ _k8s_kubeconfig | default(omit) }}"
api_key: "{{ cifmw_openshift_token | default(omit) }}"
context: "{{ cifmw_openshift_context | default(omit) }}"
api_version: dataplane.openstack.org/v1beta1
kind: OpenStackDataPlaneNodeSet
namespace: "{{ cifmw_kustomize_deploy_namespace | default('openstack') }}"
register: _verify_nodeset
failed_when: false

- name: Display verification results
ansible.builtin.debug:
msg: |
╔══════════════════════════════════════════════════════════════════╗
║ Cleanup Verification ║
╚══════════════════════════════════════════════════════════════════╝

✓ OpenStackControlPlane CRs: {{ (_verify_controlplane.resources | default([]) | length == 0) | ternary('✓ Removed', '✗ Still present (' + (_verify_controlplane.resources | default([]) | length | string) + ')') }}
✓ OpenStackDataPlaneNodeSet CRs: {{ (_verify_nodeset.resources | default([]) | length == 0) | ternary('✓ Removed', '✗ Still present (' + (_verify_nodeset.resources | default([]) | length | string) + ')') }}

{% if (_verify_controlplane.resources | default([]) | length > 0) or (_verify_nodeset.resources | default([]) | length > 0) %}
⚠ Warning: Some CRs were not fully removed. Consider:
- Running cleanup again
- Using -e force_remove_finalizers=true
- Manually investigating stuck resources
{% else %}
═══════════════════════════════════════════════════════════════════
✓ Cleanup verified successfully! Cluster ready for reuse.
═══════════════════════════════════════════════════════════════════
{% endif %}
12 changes: 12 additions & 0 deletions docs/dictionary/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ buildah
buildpkgs
cacert
cacheable
certmanager
catalogsource
cci
ccitredhat
Expand Down Expand Up @@ -138,6 +139,7 @@ deepscrub
delorean
deployer
deprovision
deprovisioned
deps
dest
dev
Expand Down Expand Up @@ -185,6 +187,7 @@ extraRPMs
ezzmy
favorit
fbqufbqkfbzxrja
finalizers
fci
fdp
fedoraproject
Expand Down Expand Up @@ -299,6 +302,7 @@ kvm
lacp
lajly
LDAP
Lifecycle
ldp
libguestfs
libvirt
Expand Down Expand Up @@ -415,8 +419,12 @@ openstack
openstackclient
openstackcontrolplane
openstackdataplane
openstackdataplanedeployment
OpenStackDataPlaneDeployment
openstackdataplanenodeset
openstackdataplanenodesets
openstackdataplaneservice
OpenStackDataPlaneService
openstackprovisioner
openstacksdk
openstackversion
Expand All @@ -443,6 +451,8 @@ passwd
passwordless
pastebin
pem
persistentvolumes
PersistentVolumes
pkgs
pki
png
Expand All @@ -468,6 +478,7 @@ pubkey
publicdomain
pullsecret
pvs
PVCs
pwd
pxe
py
Expand All @@ -491,6 +502,7 @@ readmes
readthedocs
reauthenticate
rebaser
reusability
redfish
redhat
refspec
Expand Down
Loading
Loading