summaryrefslogtreecommitdiffstats
path: root/playbooks/libvirt/openshift-cluster/terminate.yml
blob: cc95ec6806b06cc5e606d5b9e172149535307160 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
# TODO: does not handle a non-existant cluster gracefully

- name: Terminate instance(s)
  hosts: localhost
  become: no
  connection: local
  gather_facts: no
  vars_files:
  - vars.yml
  tasks:
  - set_fact: cluster_group=tag_clusterid-{{ cluster_id }}
  - add_host:
      name: "{{ item }}"
      groups: oo_hosts_to_terminate
      ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
      ansible_become: "{{ deployment_vars[deployment_type].sudo }}"
    with_items: groups[cluster_group] | default([])

- name: Unsubscribe VMs
  hosts: oo_hosts_to_terminate
  vars_files:
  - vars.yml
  roles:
  - role: rhel_unsubscribe
    when: deployment_type in ['atomic-enterprise', 'enterprise', 'openshift-enterprise'] and
          ansible_distribution == "RedHat" and
          lookup('oo_option', 'rhel_skip_subscription') | default(rhsub_skip, True) |
            default('no', True) | lower in ['no', 'false']

- name: Terminate instance(s)
  hosts: localhost
  become: no
  connection: local
  gather_facts: no
  vars_files:
  - vars.yml
  tasks:
  - name: Destroy VMs
    virt:
      name: '{{ item[0] }}'
      command: '{{ item[1] }}'
      uri: '{{ libvirt_uri }}'
    with_nested:
    - groups['oo_hosts_to_terminate']
    - [ destroy, undefine ]

  - name: Delete VM drives
    command: 'virsh -c {{ libvirt_uri }} vol-delete --pool {{ libvirt_storage_pool }} {{ item }}.qcow2'
    args:
      removes: '{{ libvirt_storage_pool_path }}/{{ item }}.qcow2'
    with_items: groups['oo_hosts_to_terminate']

  - name: Delete VM docker drives
    command: 'virsh -c {{ libvirt_uri }} vol-delete --pool {{ libvirt_storage_pool }} {{ item }}-docker.qcow2'
    args:
      removes: '{{ libvirt_storage_pool_path }}/{{ item }}-docker.qcow2'
    with_items: groups['oo_hosts_to_terminate']

  - name: Delete the VM cloud-init image
    file:
      path: '{{ libvirt_storage_pool_path }}/{{ item }}_cloud-init.iso'
      state: absent
    with_items: groups['oo_hosts_to_terminate']

  - name: Remove the cloud-init config directory
    file:
      path: '{{ libvirt_storage_pool_path }}/{{ item }}_configdrive/'
      state: absent
    with_items: groups['oo_hosts_to_terminate']