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.

30 lines
808 B

  1. ---
  2. - name: See if node is in ready state
  3. shell: "kubectl get nodes | grep {{ inventory_hostname }}"
  4. register: kubectl_nodes
  5. delegate_to: "{{ groups['kube-master'][0] }}"
  6. failed_when: false
  7. - set_fact:
  8. needs_cordoning: >-
  9. {% if " Ready" in kubectl_nodes.stdout %}
  10. true
  11. {% else %}
  12. false
  13. {% endif %}
  14. - name: Cordon node
  15. command: "{{ bin_dir }}/kubectl cordon {{ ansible_hostname }}"
  16. delegate_to: "{{ groups['kube-master'][0] }}"
  17. when: needs_cordoning
  18. - name: Drain node
  19. command: >-
  20. {{ bin_dir }}/kubectl drain
  21. --force
  22. --ignore-daemonsets
  23. --grace-period {{ drain_grace_period }}
  24. --timeout {{ drain_timeout }}
  25. --delete-local-data {{ ansible_hostname }}
  26. delegate_to: "{{ groups['kube-master'][0] }}"
  27. when: needs_cordoning