set_default_node_role.yml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ---
  2. - delegate_to: '{{ openshift_master_host }}'
  3. run_once: true
  4. block:
  5. - name: Retrieve nodes that are marked with the infra selector or the legacy infra selector
  6. oc_obj:
  7. state: list
  8. kind: Node
  9. selector: '{{ openshift_hosted_infra_selector | default("region=infra") }}'
  10. register: infra_nodes_by_selector
  11. - name: Label infra or legacy infra nodes with the new role label
  12. oc_label:
  13. name: '{{ item }}'
  14. kind: node
  15. state: add
  16. labels:
  17. - key: node-role.kubernetes.io/infra
  18. value: 'true'
  19. with_items: "{{ infra_nodes_by_selector.results.results.0['items'] | map(attribute='metadata') | map(attribute='name') | list }}"
  20. - name: Retrieve non-infra, non-master nodes that are not yet labeled compute
  21. oc_obj:
  22. state: list
  23. kind: Node
  24. selector: '{{ (openshift_hosted_infra_selector | default("node-role.kubernetes.io/infra=true")) | regex_replace("=", "!=") }},node-role.kubernetes.io/infra!=true,node-role.kubernetes.io/master!=true,node-role.kubernetes.io/compute!=true'
  25. register: non_master_non_infra_nodes_result
  26. - name: label non-master non-infra nodes compute
  27. oc_label:
  28. name: '{{ item }}'
  29. kind: node
  30. state: add
  31. labels:
  32. - key: node-role.kubernetes.io/compute
  33. value: 'true'
  34. with_items: "{{ non_master_non_infra_nodes_result.results.results.0['items'] | map(attribute='metadata') | map(attribute='name') | list }}"
  35. - name: Label all-in-one master as a compute node
  36. oc_label:
  37. name: '{{ openshift.node.nodename }}'
  38. kind: node
  39. state: add
  40. labels:
  41. - key: node-role.kubernetes.io/compute
  42. value: 'true'
  43. when: groups['oo_nodes_to_config'] | default([]) | union(groups['oo_nodes_to_bootstrap'] | default([])) | union(groups['oo_masters_to_config']) | length == 1