Repository navigation
PVE Remove Guests Playbook
Thhe pve_remove_guests.yml playbook will remove Guest machines from the PVE cluster. It first provide a list of the matched guest machines and prompt for confirmation before doing anything. It then cleans up entries in the ~/.ssh/known_hosts file on the control node, then stops the guest machines, and finally destroys them.
This provides a quick method of cleaning up one or more guest machines. For example, when a set of VMs were created for running a Kubernetes cluster. Or even to remove all the guest machines on a PVE cluster in order to start with a clean slate.
Set the remove_host_patterns variable to a pattern of host machines to be removed. This value is treated the same as those used by the hosts: keyword in plays and will return a list of matching hosts from inventory. Because this is a destructive operation, remember that the role will first prompt for confirmation of removal and show the matched hosts.
Most commands below use -i lab-minimal because there is no reason to gather facts.
cloudcodger.proxmox_client.remove
- Showcase prerequisites.
Run the playbook according to one of these examples.
ansible-playbook -i lab-minimal pve_remove_guests.yml -e remove_host_patterns=builder
ansible-playbook -i lab-minimal pve_remove_guests.yml -e remove_host_patterns=name_server,ns_single,ns_split,ns_vmRunning the playbook without setting remove_host_patterns will attempt to remove an empty list and do nothing.
ansible-playbook -i lab-minimal pve_remove_guests.ymlTo remove ALL the guest machines from a PVE cluster, select all the CTs and VMs. This is only intended to be done on a small lab and caution must be taken to not destroy production machines.
ansible-playbook -i lab-minimal pve_remove_guests.yml -e remove_host_patterns=proxmox_all_lxc,proxmox_all_qemuKeep in mind that using a pattern like k0s as an Ansible group that was created from PVE tags requires the lab inventory directory, which has want_facts enabled.
ansible-playbook -i lab pve_remove_guests.yml -e remove_host_patterns=k0sOtherwise, they can be removed using wildcard patterns, like this.
ansible-playbook -i lab-minimal pve_remove_guests.yml -e remove_host_patterns=ctrl\*,work\*The pve_remove_guests.yml playbook contains a single play.
Roles run:
-
cloudcodger.proxmox_client.removeto:- remove maching guest machines from the SSH
known_hostsfile - forcefully stop matching guest machines
- remove the matching guest machines
- remove maching guest machines from the SSH