main.yml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ---
  2. - name: Create temp directory for kubeconfig
  3. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  4. register: mktemp
  5. changed_when: False
  6. - name: Copy the admin client config(s)
  7. command: >
  8. cp {{ openshift_master_config_dir }}/admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  9. changed_when: False
  10. - name: Determine if projects exist
  11. command: >
  12. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
  13. get projects {{ item.key }} -o json
  14. with_dict: "{{ openshift_projects }}"
  15. failed_when: false
  16. changed_when: false
  17. register: project_test
  18. - name: Create projects
  19. command: >
  20. {{ openshift.common.admin_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
  21. new-project {{ item.item.key }}
  22. {% if item.item.value.default_node_selector | default(none) != none %}
  23. {{ '--node-selector=' ~ item.item.value.default_node_selector }}
  24. {% endif %}
  25. when: item.rc == 1
  26. with_items:
  27. - "{{ project_test.results }}"
  28. - name: Update project default node selector if necessary
  29. command: >
  30. {{ openshift.common.client_binary }}
  31. --config={{ mktemp.stdout }}/admin.kubeconfig patch namespace {{ item.item.key }}
  32. -p '{"metadata": {"annotations": {"openshift.io/node-selector": "{{ item.item.value.default_node_selector }}"}}}'
  33. when: "{{ item.rc == 0 and item.item.value.default_node_selector | default(none) != none
  34. and item.item.value.default_node_selector | default(none) != (item.stdout | from_json).metadata.annotations['openshift.io/node-selector'] | default(none) }}"
  35. with_items:
  36. - "{{ project_test.results }}"
  37. register: annotate_project
  38. - name: Delete temp directory
  39. file:
  40. name: "{{ mktemp.stdout }}"
  41. state: absent
  42. changed_when: False