router.yml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. when: openshift.hosted.router.replicas | default(None) == None
  32. - name: Collect nodes matching router selector
  33. set_fact:
  34. openshift_hosted_router_nodes: >
  35. {{ (openshift_hosted_router_nodes_json.stdout|from_json)['items']
  36. | oo_oc_nodes_matching_selector(openshift.hosted.router.selector) }}
  37. when: openshift.hosted.router.replicas | default(None) == None
  38. - name: Create OpenShift router
  39. command: >
  40. {{ openshift.common.admin_binary }} router --create
  41. {% if openshift.hosted.router.replicas | default(None) != None -%}
  42. --replicas={{ openshift.hosted.router.replicas }}
  43. {% else -%}
  44. --replicas={{ openshift_hosted_router_nodes | length }}
  45. {% endif %}
  46. {% if openshift.hosted.router.certificate | default(None) != None -%}
  47. --default-cert={{ openshift_master_config_dir }}/openshift-router.pem
  48. {% endif -%}
  49. --namespace=default
  50. --service-account=router
  51. --selector='{{ openshift.hosted.router.selector }}'
  52. --credentials={{ openshift_master_config_dir }}/openshift-router.kubeconfig
  53. {% if openshift.hosted.router.registryurl | default(None)!= None -%}
  54. --images='{{ openshift.hosted.router.registryurl }}'
  55. {% endif -%}
  56. register: openshift_hosted_router_results
  57. changed_when: "'service exists' not in openshift_hosted_router_results.stdout"
  58. when: openshift.hosted.router.replicas | default(None) != None or (openshift_hosted_router_nodes is defined and openshift_hosted_router_nodes | length > 0)