|
40 | 40 | - name: Register if we need to do a etcd restore from s3 |
41 | 41 | ansible.builtin.set_fact: |
42 | 42 | do_etcd_restore_from_s3: true |
43 | | - when: not rke2_etcd_snapshot_file and rke2_etcd_snapshot_s3_options is defined and rke2_etcd_snapshot_s3_options.access_key and rke2_etcd_snapshot_s3_options.secret_key and rke2_etcd_snapshot_s3_options.bucket and rke2_etcd_snapshot_s3_options.snapshot_name |
| 43 | + when: |
| 44 | + - not rke2_etcd_snapshot_file |
| 45 | + - rke2_etcd_snapshot_s3_options is defined |
| 46 | + - rke2_etcd_snapshot_s3_options.access_key |
| 47 | + - rke2_etcd_snapshot_s3_options.secret_key |
| 48 | + - rke2_etcd_snapshot_s3_options.bucket |
| 49 | + - rke2_etcd_snapshot_s3_options.snapshot_name |
44 | 50 |
|
45 | 51 | - name: Restore etcd from file |
46 | 52 | when: do_etcd_restore is defined |
|
138 | 144 | - not ansible_check_mode |
139 | 145 | - rke2_cni != 'none' |
140 | 146 |
|
141 | | -- name: Restore etcd - remove old <node>.node-password.rke2 secrets |
142 | | - ansible.builtin.shell: | |
143 | | - {{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \ |
144 | | - delete secret {{ item }}.node-password.rke2 -n kube-system 2>&1 || true |
145 | | - args: |
146 | | - executable: /bin/bash |
147 | | - with_items: "{{ groups[rke2_cluster_group_name] }}" |
148 | | - changed_when: false |
149 | | - when: not ansible_check_mode and inventory_hostname != item and (do_etcd_restore is defined or do_etcd_restore_from_s3 is defined) |
| 147 | +- name: Restore etcd |
| 148 | + when: do_etcd_restore is defined or do_etcd_restore_from_s3 is defined |
| 149 | + block: |
| 150 | + - name: Get registered nodes |
| 151 | + ansible.builtin.shell: | |
| 152 | + {{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \ |
| 153 | + get nodes --no-headers | awk '{print $1}' |
| 154 | + args: |
| 155 | + executable: /bin/bash |
| 156 | + changed_when: false |
| 157 | + register: registered_node_names |
| 158 | + |
| 159 | + - name: Get all node names |
| 160 | + ansible.builtin.set_fact: |
| 161 | + node_names: "{{ hostvars | dict2items | map(attribute='value.rke2_node_name') }}" |
| 162 | + run_once: true |
| 163 | + register: node_names |
| 164 | + |
| 165 | + - name: remove old <node>.node-password.rke2 secrets |
| 166 | + ansible.builtin.shell: | |
| 167 | + {{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \ |
| 168 | + delete secret {{ item }}.node-password.rke2 -n kube-system 2>&1 || true |
| 169 | + args: |
| 170 | + executable: /bin/bash |
| 171 | + with_items: "{{ registered_node_names.stdout_lines | difference(node_names) }}" |
| 172 | + changed_when: false |
| 173 | + |
| 174 | + - name: remove old nodes |
| 175 | + ansible.builtin.shell: | |
| 176 | + {{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \ |
| 177 | + delete node {{ item }} 2>&1 || true |
| 178 | + args: |
| 179 | + executable: /bin/bash |
| 180 | + with_items: "{{ registered_node_names.stdout_lines | difference(node_names) }}" |
| 181 | + changed_when: false |
150 | 182 |
|
151 | 183 | - name: Set an Active Server variable |
152 | 184 | ansible.builtin.set_fact: |
|
0 commit comments