commit | author | age
|
928f77
|
1 |
--- |
GC |
2 |
- name: Delete Infrastructure |
|
3 |
hosts: localhost |
|
4 |
connection: local |
|
5 |
gather_facts: False |
|
6 |
become: no |
|
7 |
vars_files: |
|
8 |
- "{{ANSIBLE_REPO_PATH}}/configs/{{env_type}}/env_vars.yml" |
|
9 |
- "{{ANSIBLE_REPO_PATH}}/configs/{{env_type}}/env_secret_vars.yml" |
|
10 |
environment: |
|
11 |
AZURE_CLIENT_ID: "{{azure_service_principal}}" |
|
12 |
AZURE_TENANT: "{{azure_tenant}}" |
|
13 |
AZURE_SECRET: "{{azure_password}}" |
|
14 |
AZURE_SUBSCRIPTION_ID: "{{azure_subscription_id}}" |
|
15 |
# AZURE_CONFIG_DIR: create a specific config dir for this stack to allow concurrent access for 'az' command |
|
16 |
AZURE_CONFIG_DIR: "/tmp/.azure-{{project_tag}}" |
|
17 |
tasks: |
ef668f
|
18 |
- name: Delete delegation for NS to the main DNSZone |
GC |
19 |
azure_rm_dnsrecordset: |
|
20 |
resource_group: "{{az_dnszone_resource_group|default('dns')}}" |
|
21 |
relative_name: "{{guid}}" |
|
22 |
zone_name: "{{HostedZoneId}}" |
|
23 |
record_type: NS |
|
24 |
state: absent |
|
25 |
|
3cc138
|
26 |
- name: Destroy method resourceGroup (standalone ResourceGroup) |
GC |
27 |
when: az_destroy_method|default('resource_group') == 'resource_group' |
|
28 |
block: |
15b4ac
|
29 |
- name: Delete the resource group |
GC |
30 |
azure_rm_resourcegroup: |
|
31 |
name: "{{az_resource_group}}" |
|
32 |
state: absent |
|
33 |
force: true |
|
34 |
tags: |
|
35 |
- destroying |
|
36 |
- destroy_cloud_deployment |
|
37 |
- destroy_azure_deployment |
|
38 |
register: azure_result |
|
39 |
until: azure_result|succeeded |
|
40 |
retries: 6 |
|
41 |
delay: 10 |
|
42 |
ignore_errors: yes |
|
43 |
when: |
|
44 |
- cloud_provider == 'azure' |
928f77
|
45 |
|
15b4ac
|
46 |
- name: report azure error |
GC |
47 |
fail: |
|
48 |
msg: "FAIL {{ az_resource_group }} Azure delete group" |
|
49 |
when: |
|
50 |
- not azure_result|succeeded |
|
51 |
- cloud_provider == 'azure' |
|
52 |
tags: |
|
53 |
- destroying |
|
54 |
- destroy_cloud_deployment |
|
55 |
- destroy_azure_deployment |
3cc138
|
56 |
|
GC |
57 |
- name: Method destroy deployment (shared ResourceGroup) |
|
58 |
when: az_destroy_method|default('resource_group') == 'deployment' |
|
59 |
environment: |
|
60 |
AZURE_CLIENT_ID: "{{azure_service_principal}}" |
|
61 |
AZURE_TENANT: "{{azure_tenant}}" |
|
62 |
AZURE_SECRET: "{{azure_password}}" |
|
63 |
AZURE_SUBSCRIPTION_ID: "{{azure_subscription_id}}" |
|
64 |
# AZURE_CONFIG_DIR: create a specific config dir for this stack to allow concurrent access |
|
65 |
AZURE_CONFIG_DIR: "/tmp/.azure-{{project_tag}}" |
|
66 |
block: |
15b4ac
|
67 |
- set_fact: |
GC |
68 |
t_dest: "{{ANSIBLE_REPO_PATH}}/workdir/{{ env_type }}.{{ guid }}.{{cloud_provider}}_cloud_template" |
3cc138
|
69 |
|
15b4ac
|
70 |
- name: Get all resources from the deployment |
GC |
71 |
command: az group deployment show --name {{env_type}}.{{guid}} --resource-group {{az_resource_group}} |
|
72 |
changed_when: false |
|
73 |
register: az_dep |
|
74 |
until: az_dep|succeeded |
|
75 |
retries: 5 |
3cc138
|
76 |
|
15b4ac
|
77 |
- debug: |
GC |
78 |
var: az_dep |
|
79 |
verbosity: 2 |
3cc138
|
80 |
|
15b4ac
|
81 |
- name: Get all resources from tag |
GC |
82 |
command: az resource list --tag 'Project={{project_tag}}' |
|
83 |
register: az_tag |
|
84 |
restries: 5 |
|
85 |
until: az_tag|succeeded |
|
86 |
changed_when: false |
3cc138
|
87 |
|
15b4ac
|
88 |
- name: delete all resources |
GC |
89 |
vars: |
|
90 |
ids_tags: "{{ az_tag.stdout|from_json|json_query('[*].id')}}" |
|
91 |
ids_deployment: "{{ az_dep.stdout|from_json|json_query('properties.additionalProperties.outputResources[*].id')}}" |
|
92 |
ids: "{{ids_deployment|union(ids_tags)}}" |
|
93 |
command: "az resource delete --ids {{ids|join(' ')}} --resource-group {{az_resource_group}}" |
|
94 |
register: az_delete |
|
95 |
until: az_delete|succeeded |
|
96 |
retries: 5 |
|
97 |
when: ids|length > 0 |