2020-06-09 12:37:17 +00:00
|
|
|
---
|
2020-07-04 09:02:48 +00:00
|
|
|
- name: Lookup node IP in kubernetes
|
|
|
|
shell: >-
|
|
|
|
{{ bin_dir }}/kubectl get nodes {{ node }}
|
|
|
|
-o jsonpath='{range.status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}'
|
|
|
|
register: remove_node_ip
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- ip is not defined
|
|
|
|
- access_ip is not defined
|
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
|
|
|
failed_when: false
|
|
|
|
|
2020-06-09 12:37:17 +00:00
|
|
|
- name: Set node IP
|
|
|
|
set_fact:
|
|
|
|
node_ip: "{{ ip | default(access_ip | default(remove_node_ip.stdout)) | trim }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
|
2020-09-01 08:05:58 +00:00
|
|
|
- name: Make sure node_ip is set
|
|
|
|
assert:
|
|
|
|
that: node_ip is defined and node_ip | length > 0
|
|
|
|
msg: "Etcd node ip is not set !"
|
2020-09-19 00:14:27 +00:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
2020-09-01 08:05:58 +00:00
|
|
|
|
2020-06-09 12:37:17 +00:00
|
|
|
- name: Lookup etcd member id
|
2020-07-27 06:32:29 +00:00
|
|
|
shell: "{{ bin_dir }}/etcdctl member list | grep {{ node_ip }} | cut -d, -f1"
|
2020-06-09 12:37:17 +00:00
|
|
|
register: etcd_member_id
|
2021-07-12 07:00:47 +00:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2020-06-09 12:37:17 +00:00
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
environment:
|
2020-07-20 14:26:51 +00:00
|
|
|
ETCDCTL_API: 3
|
2021-06-07 12:02:40 +00:00
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}-key.pem"
|
2020-07-20 14:26:51 +00:00
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
2021-06-07 12:02:40 +00:00
|
|
|
ETCDCTL_ENDPOINTS: "https://{{ hostvars[groups['etcd']|first]['etcd_access_address'] |
|
|
|
|
default(hostvars[groups['etcd']|first]['ip']) |
|
|
|
|
default(hostvars[groups['etcd']|first]['fallback_ips'][groups['etcd']|first]) }}:2379"
|
2020-06-09 12:37:17 +00:00
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
2020-07-20 14:26:51 +00:00
|
|
|
when: inventory_hostname in groups['etcd']
|
2020-06-09 12:37:17 +00:00
|
|
|
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: Remove etcd member from cluster
|
|
|
|
command: "{{ bin_dir }}/etcdctl member remove {{ etcd_member_id.stdout }}"
|
2020-06-09 12:37:17 +00:00
|
|
|
register: etcd_member_in_cluster
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
environment:
|
2020-07-20 14:26:51 +00:00
|
|
|
ETCDCTL_API: 3
|
2021-06-07 12:02:40 +00:00
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}-key.pem"
|
2020-07-20 14:26:51 +00:00
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
2021-06-07 12:02:40 +00:00
|
|
|
ETCDCTL_ENDPOINTS: "https://{{ hostvars[groups['etcd']|first]['etcd_access_address'] |
|
|
|
|
default(hostvars[groups['etcd']|first]['ip']) |
|
|
|
|
default(hostvars[groups['etcd']|first]['fallback_ips'][groups['etcd']|first]) }}:2379"
|
2020-06-09 12:37:17 +00:00
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- etcd_member_id.stdout | length > 0
|
2021-12-01 15:17:15 +00:00
|
|
|
|
|
|
|
# Delete node from kubeadm-config
|
|
|
|
- name: Update kubeadm-config configmap removing control-plane no longer existing endpoints
|
|
|
|
vars:
|
|
|
|
kubeadm_config_cm_content: "{{ lookup('kubernetes.core.k8s', kind='ConfigMap', namespace='kube-system', resource_name='kubeadm-config', kubeconfig=keos_kubeconfig_path) }}"
|
|
|
|
kubernetes.core.k8s:
|
|
|
|
kubeconfig: "{{ keos_kubeconfig_path }}"
|
|
|
|
definition:
|
|
|
|
api_version: v1
|
|
|
|
kind: ConfigMap
|
|
|
|
metadata:
|
|
|
|
name: kubeadm-config-test
|
|
|
|
namespace: default
|
|
|
|
data:
|
|
|
|
ClusterStatus: "{{ kubeadm_config_cm_content.data.ClusterStatus | regex_replace( node |default(kube_node) + ':\n' + ' *advertiseAddress: ([0-9]{1,3}.){3}[0-9]{1,3}\n' + ' *bindPort: [0-9]{1,5}' , '') }}"
|