summaryrefslogtreecommitdiffstats
path: root/playbooks/openstack/openshift-cluster/terminate.yml
blob: 2a7f0450593da1296fd5442094cdd50ba8c3b1b7 (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
- name: Terminate instance(s)
  hosts: localhost
  become: no
  connection: local
  gather_facts: no
  vars_files:
  - vars.yml
  tasks:
  - set_fact: cluster_group=tag_env_{{ cluster_id }}
  - add_host:
      name: "{{ item }}"
      groups: oo_hosts_to_terminate
      ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
      ansible_sudo: "{{ 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 == "enterprise" and
          ansible_distribution == "RedHat" and
          lookup('oo_option', 'rhel_skip_subscription') | default(rhsub_skip, True) |
            default('no', True) | lower in ['no', 'false']

- hosts: localhost
  become: no
  connection: local
  gather_facts: no
  vars_files:
  - vars.yml
  tasks:
  - name: Delete the OpenStack Stack
    command: 'heat stack-delete openshift-ansible-{{ cluster_id }}-stack'
    register: stack_delete_result
    changed_when: stack_delete_result.rc == 0
    failed_when: stack_delete_result.rc != 0 and 'could not be found' not in stack_delete_result.stdout

  - name: Wait for the completion of the OpenStack Stack deletion
    shell: 'heat stack-show openshift-ansible-{{ cluster_id }}-stack | awk ''$2 == "stack_status" {print $4}'''
    when: stack_delete_result.changed
    register: stack_show_result
    until: stack_show_result.stdout != 'DELETE_IN_PROGRESS'
    retries: 60
    delay: 1
    failed_when: '"Stack not found" not in stack_show_result.stderr and
                   stack_show_result.stdout != "DELETE_COMPLETE"'