-
Notifications
You must be signed in to change notification settings - Fork 4
/
cloud-init-iso-cleanup.yml
43 lines (37 loc) · 2.03 KB
/
cloud-init-iso-cleanup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
#note - this exposed an issue where mounted iso's can be deleted from media library via api resulting in VM's that can't live migrate while iso ephemeral clone is still attached to vm
- name: Clean up previously used cloud-init-* iso images
hosts: edge # use ansible-playbook -l group to limit application to specific groups - has tab completion for -l !
connection: ansible.builtin.local
gather_facts: false
strategy: host_pinned #allows each cluster to start next task before all clusters have finished current task
environment: # if set here - hypercore modules will automatically use this for each remote cluster - avoiding need to specify cluster_instance for each test
SC_HOST: "https://{{ inventory_hostname }}"
SC_USERNAME: "{{ scale_user }}"
SC_PASSWORD: "{{ scale_pass }}"
SC_TIMEOUT: 10000
vars:
mount_limit: 0 # change to 1 or higher to deleted mounted cloud-init isos - 0 will only delete "orphaned" and unmounted cloud-init-*.iso s
# Api / iso module will allow ISO media to be deleted even if mounted by VMs. If VM is running they will still have access to ephemeral copy until VM domain is stopped
tasks:
- name: get all vm info
scale_computing.hypercore.vm_info:
register: vm_info
- name: output vm_info
ansible.builtin.debug:
msg: "{{ vm_info }}"
# need vm_info.records.disks.iso_name - is there a way to get all disks on cluster? appears not
# for original problem - iso_info does return vms with media mounted - could use that to eject iso before deleting media
# for current cleanup easiest may be playbook to stop and restart all VMs - steal code from single node update?
- name: Get hypercore iso info
scale_computing.hypercore.iso_info:
register: iso_info
- name: Output iso_info
ansible.builtin.debug:
var: iso_info
- name: Delete cloud-init isos based on mount_limit
scale_computing.hypercore.iso:
name: "{{ item.name }}"
state: absent
when: item.mounts | length == mount_limit and 'cloud-init-' in item.name
loop: "{{ iso_info.records }}"