router.yml 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ---
  2. - fail:
  3. msg: "Both 'certfile' and 'keyfile' keys must be specified when supplying the openshift_hosted_router_certificate variable."
  4. when: openshift_hosted_router_certificate is defined and ('certfile' not in openshift_hosted_router_certificate or 'keyfile' not in openshift_hosted_router_certificate)
  5. - name: Read router certificate and key
  6. slurp:
  7. src: "{{ item }}"
  8. register: openshift_router_certificate_output
  9. with_items:
  10. - "{{ openshift_hosted_router_certificate.certfile }}"
  11. - "{{ openshift_hosted_router_certificate.keyfile }}"
  12. delegate_to: localhost
  13. when: openshift_hosted_router_certificate is defined
  14. - name: Persist certificate contents
  15. openshift_facts:
  16. role: hosted
  17. openshift_env:
  18. openshift_hosted_router_certificate_contents: "{% for certificate in openshift_router_certificate_output.results -%}{{ certificate.content | b64decode }}{% endfor -%}"
  19. when: openshift_hosted_router_certificate is defined
  20. - name: Create PEM certificate
  21. copy:
  22. content: "{{ openshift.hosted.router.certificate.contents }}"
  23. dest: "{{ openshift_master_config_dir }}/openshift-router.pem"
  24. mode: 0600
  25. when: openshift.hosted.router.certificate | default(None) != None
  26. - name: Retrieve list of openshift nodes
  27. command: >
  28. {{ openshift.common.client_binary }} --api-version='v1' -o json
  29. get nodes -n default --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  30. register: openshift_hosted_router_nodes_json
  31. changed_when: false
  32. when: openshift.hosted.router.replicas | default(None) == None
  33. - name: Collect nodes matching router selector
  34. set_fact:
  35. openshift_hosted_router_nodes: >
  36. {{ (openshift_hosted_router_nodes_json.stdout|from_json)['items']
  37. | oo_oc_nodes_matching_selector(openshift.hosted.router.selector) }}
  38. when: openshift.hosted.router.replicas | default(None) == None
  39. - name: Create OpenShift router
  40. command: >
  41. {{ openshift.common.admin_binary }} router --create
  42. {% if openshift.hosted.router.replicas | default(None) != None -%}
  43. --replicas={{ openshift.hosted.router.replicas }}
  44. {% else -%}
  45. --replicas={{ openshift_hosted_router_nodes | length }}
  46. {% endif %}
  47. {% if openshift.hosted.router.certificate | default(None) != None -%}
  48. --default-cert={{ openshift_master_config_dir }}/openshift-router.pem
  49. {% endif -%}
  50. --namespace=default
  51. --service-account=router
  52. --selector='{{ openshift.hosted.router.selector }}'
  53. --credentials={{ openshift_master_config_dir }}/openshift-router.kubeconfig
  54. {% if openshift.hosted.router.registryurl | default(None)!= None -%}
  55. --images='{{ openshift.hosted.router.registryurl }}'
  56. {% endif -%}
  57. register: openshift_hosted_router_results
  58. changed_when: "'service exists' not in openshift_hosted_router_results.stdout"
  59. when: openshift.hosted.router.replicas | default(None) != None or (openshift_hosted_router_nodes is defined and openshift_hosted_router_nodes | length > 0)