-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdelete.yaml
80 lines (69 loc) · 3.03 KB
/
delete.yaml
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
72
73
74
75
76
77
78
79
80
# Copyright 2023 CS Group
#
# 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.
---
- name: Deleting the cluster, and the created files
hosts: localhost
tasks:
- name: Add default value for safescale values
set_fact:
safescale_path: "{{ safescale_path | default('$(command -v safescale)') }}"
- name: Detach volumes
block:
- name: Getting attached volume list
shell: "{{ safescale_path }} volume list | jq -r '.result[] | select((.name? | match({{ cluster.name }}-node-[0-9]+-.*)) and .attachments != null).name'"
register: attached_volume_names
- name: Detach volumes from nodes
shell: "{{ safescale_path }} volume detach {{ item }} {{ item | regex_search(cluster.name+\"-node-[0-9]+\",'\\0') | first }} "
when: attached_volume_names.stdout_lines | length > 0
loop: "{{ attached_volume_names.stdout_lines }}"
async: 30
poll: 0
tags: [ 'never', 'detach_volumes' ]
- block:
- name: Getting volume list
shell: "{{ safescale_path }} volume list | jq -r '.result[] | select(.name? | match({{ cluster.name }}-node-[0-9]+-.*)).name'"
register: volume_names
- name: Deleting the volumes
shell: "{{ safescale_path }} volume delete {{ item }}"
loop: "{{ volume_names.stdout_lines }}"
async: 30
poll: 0
when: volume_names.stdout_lines | length > 0
tags: [ 'never', 'delete_volumes' ]
- name: Deleting the cluster
shell: "{{ safescale_path }} cluster delete -y {{ cluster.name }}"
ignore_errors: yes
tags: [ 'never', 'delete_cluster' ]
- name: cleanup repo
block:
- name: clean hosts file
blockinfile:
path: "{{ inventory_dir }}/hosts.yaml"
marker: "# {mark} ANSIBLE MANAGED BLOCK"
- name: Deleting ssh keys, artifacts and ssh-main-gateway files
file:
state: absent
path: "{{ item }}"
loop:
- "{{ playbook_dir }}/ssh-main-gateway.conf"
- "{{ inventory_dir }}/artifacts"
tags: [ 'never', 'cleanup_generated' ]
- block:
- name: Get bucket list
shell: "{{ safescale_path }} bucket list"
register: safescale_buckets
- name: Delete s3 buckets
shell: "{{ safescale_path }} bucket delete {{ item }}"
loop: "{{ (safescale_buckets.stdout | from_json).result.buckets | map(attribute='name') | select('match', cluster.name ~ '-.*') }}"
tags: [ 'never', 'delete_buckets' ]