label_node.yaml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ---
  2. - command: >
  3. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get node {{host}}
  4. -o jsonpath='{.metadata.labels}'
  5. register: node_labels
  6. when: not ansible_check_mode
  7. changed_when: no
  8. - command: >
  9. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig label node {{host}} {{label}}={{value}}
  10. register: label_result
  11. failed_when: label_result.rc == 1 and 'exists' not in label_result.stderr
  12. when:
  13. - value is defined
  14. - node_labels.stdout is defined
  15. - label not in node_labels.stdout
  16. - unlabel is not defined or not unlabel
  17. - not ansible_check_mode
  18. - command: >
  19. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig get node {{host}}
  20. -o jsonpath='{.metadata.labels.{{ label }}}'
  21. register: label_value
  22. ignore_errors: yes
  23. changed_when: no
  24. when:
  25. - value is defined
  26. - node_labels.stdout is defined
  27. - label in node_labels.stdout
  28. - unlabel is not defined or not unlabel
  29. - not ansible_check_mode
  30. - command: >
  31. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig label node {{host}} {{label}}={{value}} --overwrite
  32. register: label_result
  33. failed_when: label_result.rc == 1 and 'exists' not in label_result.stderr
  34. when:
  35. - value is defined
  36. - label_value.stdout is defined
  37. - label_value.stdout != value
  38. - unlabel is not defined or not unlabel
  39. - not ansible_check_mode
  40. - command: >
  41. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig label node {{host}} {{label}}-
  42. register: label_result
  43. failed_when: label_result.rc == 1 and 'exists' not in label_result.stderr
  44. when:
  45. - unlabel is defined
  46. - unlabel
  47. - not ansible_check_mode
  48. - label in node_labels.stdout