initialize_nodes_to_upgrade.yml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ---
  2. - name: Filter list of nodes to be upgraded if necessary
  3. hosts: oo_first_master
  4. roles:
  5. - lib_openshift
  6. tasks:
  7. - name: Retrieve list of openshift nodes matching upgrade label
  8. oc_obj:
  9. state: list
  10. kind: node
  11. selector: "{{ openshift_upgrade_nodes_label }}"
  12. register: nodes_to_upgrade
  13. when: openshift_upgrade_nodes_label is defined
  14. # We got a list of nodes with the label, now we need to match these with inventory hosts
  15. # using their openshift.common.hostname fact.
  16. - name: Map labelled nodes to inventory hosts
  17. add_host:
  18. name: "{{ item }}"
  19. groups: temp_nodes_to_upgrade
  20. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  21. ansible_become: "{{ g_sudo | default(omit) }}"
  22. with_items: " {{ groups['oo_nodes_to_config'] }}"
  23. when:
  24. - openshift_upgrade_nodes_label is defined
  25. - hostvars[item].openshift.common.hostname in nodes_to_upgrade.results.results[0]['items'] | map(attribute='metadata.name') | list
  26. changed_when: false
  27. # Build up the oo_nodes_to_upgrade group, use the list filtered by label if
  28. # present, otherwise hit all nodes:
  29. - name: Evaluate oo_nodes_to_upgrade
  30. add_host:
  31. name: "{{ item }}"
  32. groups: oo_nodes_to_upgrade
  33. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  34. ansible_become: "{{ g_sudo | default(omit) }}"
  35. with_items: "{{ groups['temp_nodes_to_upgrade'] | default(groups['oo_nodes_to_config']) }}"
  36. changed_when: False