You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

  1. ---
  2. - name: Lookup node IP in kubernetes
  3. shell: >-
  4. {{ bin_dir }}/kubectl get nodes {{ node }}
  5. -o jsonpath='{range.status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}'
  6. register: remove_node_ip
  7. when:
  8. - inventory_hostname in groups['etcd']
  9. - ip is not defined
  10. - access_ip is not defined
  11. delegate_to: "{{ groups['etcd']|first }}"
  12. failed_when: false
  13. - name: Set node IP
  14. set_fact:
  15. node_ip: "{{ ip | default(access_ip | default(remove_node_ip.stdout)) | trim }}"
  16. when:
  17. - inventory_hostname in groups['etcd']
  18. - name: Make sure node_ip is set
  19. assert:
  20. that: node_ip is defined and node_ip | length > 0
  21. msg: "Etcd node ip is not set !"
  22. when:
  23. - inventory_hostname in groups['etcd']
  24. - name: Lookup etcd member id
  25. shell: "{{ bin_dir }}/etcdctl member list | grep {{ node_ip }} | cut -d, -f1"
  26. register: etcd_member_id
  27. ignore_errors: true
  28. changed_when: false
  29. check_mode: no
  30. tags:
  31. - facts
  32. environment:
  33. ETCDCTL_API: 3
  34. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  35. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  36. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  37. ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
  38. delegate_to: "{{ groups['etcd']|first }}"
  39. when: inventory_hostname in groups['etcd']
  40. - name: Remove etcd member from cluster
  41. command: "{{ bin_dir }}/etcdctl member remove {{ etcd_member_id.stdout }}"
  42. register: etcd_member_in_cluster
  43. changed_when: false
  44. check_mode: no
  45. tags:
  46. - facts
  47. environment:
  48. ETCDCTL_API: 3
  49. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  50. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  51. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  52. ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
  53. delegate_to: "{{ groups['etcd']|first }}"
  54. when:
  55. - inventory_hostname in groups['etcd']
  56. - etcd_member_id.stdout | length > 0