|
104 | 104 | dest: "{{ capi_cluster_kubeconfig_path }}" |
105 | 105 | mode: u=rw,g=,o= |
106 | 106 |
|
107 | | -- name: Including token-based kubeconfig tasks to generate token-based kubeconfig |
108 | | - when: capi_cluster_service_account_enabled |
109 | | - environment: |
110 | | - KUBECONFIG: "{{ capi_cluster_kubeconfig_path }}" |
111 | | - block: |
112 | | - - name: Include token-based kubeconfig task file |
113 | | - ansible.builtin.include_tasks: capi-cluster-service-account.yml |
| 107 | + - name: Including token-based kubeconfig tasks to generate token-based kubeconfig |
| 108 | + when: capi_cluster_service_account_enabled |
| 109 | + environment: |
| 110 | + KUBECONFIG: "{{ capi_cluster_kubeconfig_path }}" |
| 111 | + block: |
| 112 | + - name: Include token-based kubeconfig task file |
| 113 | + ansible.builtin.include_tasks: capi-cluster-service-account.yml |
114 | 114 |
|
115 | 115 | - name: Check that the cluster exists |
116 | 116 | ansible.builtin.command: >- |
117 | 117 | kubectl get |
118 | 118 | openstackclusters.infrastructure.cluster.x-k8s.io |
119 | 119 | -n {{ capi_cluster_release_namespace }} |
120 | 120 | {{ capi_cluster_release_name }} |
121 | | - ignore_errors: true |
| 121 | + --ignore-not-found true |
| 122 | + -o json |
122 | 123 | changed_when: false |
123 | 124 | register: cluster_check |
124 | 125 | when: capi_cluster_release_state == 'absent' |
125 | 126 |
|
| 127 | +- name: Set fact from cluster check |
| 128 | + ansible.builtin.set_fact: |
| 129 | + cluster_details: "{{ cluster_check.stdout | from_json }}" |
| 130 | + changed_when: false |
| 131 | + when: capi_cluster_release_state == 'absent' |
| 132 | + |
126 | 133 | - name: Delete CAPI cluster |
127 | 134 | when: |
128 | 135 | - capi_cluster_release_state == 'absent' |
129 | | - - cluster_check.rc == 0 |
| 136 | + - cluster_details.items is defined and cluster_details.items | length == 1 |
130 | 137 | block: |
131 | 138 | # Before deleting the cluster, update the annotation that indicates if volumes should be kept |
132 | 139 | - name: Set volumes policy annotation |
|
0 commit comments