router.yml 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ---
  2. - fail:
  3. msg: "'certfile', 'keyfile' and 'cafile' 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 or 'cafile' not in openshift_hosted_router_certificate)
  5. - name: Read router certificate and key
  6. become: no
  7. local_action:
  8. module: slurp
  9. src: "{{ item }}"
  10. register: openshift_router_certificate_output
  11. # Defaulting dictionary keys to none to avoid deprecation warnings
  12. # (future fatal errors) during template evaluation. Dictionary keys
  13. # won't be accessed unless openshift_hosted_router_certificate is
  14. # defined and has all keys (certfile, keyfile, cafile) which we
  15. # check above.
  16. with_items:
  17. - "{{ (openshift_hosted_router_certificate | default({'certfile':none})).certfile }}"
  18. - "{{ (openshift_hosted_router_certificate | default({'keyfile':none})).keyfile }}"
  19. - "{{ (openshift_hosted_router_certificate | default({'cafile':none})).cafile }}"
  20. when: openshift_hosted_router_certificate is defined
  21. - name: Persist certificate contents
  22. openshift_facts:
  23. role: hosted
  24. openshift_env:
  25. openshift_hosted_router_certificate_contents: "{% for certificate in openshift_router_certificate_output.results -%}{{ certificate.content | b64decode }}{% endfor -%}"
  26. when: openshift_hosted_router_certificate is defined
  27. - name: Create PEM certificate
  28. copy:
  29. content: "{{ openshift.hosted.router.certificate.contents }}"
  30. dest: "{{ openshift_master_config_dir }}/openshift-router.pem"
  31. mode: 0600
  32. when: "'certificate' in openshift.hosted.router and 'contents' in openshift.hosted.router.certificate"
  33. - name: Retrieve list of openshift nodes matching router selector
  34. command: >
  35. {{ openshift.common.client_binary }} --api-version='v1' -o json
  36. get nodes -n default --config={{ openshift_hosted_kubeconfig }}
  37. --selector={{ openshift.hosted.router.selector | default('') }}
  38. register: router_nodes_json
  39. changed_when: false
  40. when: openshift.hosted.router.replicas | default(none) is none
  41. - set_fact:
  42. replicas: "{{ openshift.hosted.router.replicas | default((router_nodes_json.stdout | default('{\"items\":[]}') | from_json)['items'] | length) }}"
  43. - name: Create OpenShift router
  44. command: >
  45. {{ openshift.common.admin_binary }} router --create
  46. --config={{ openshift_hosted_kubeconfig }}
  47. {% if replicas > 1 -%}
  48. --replicas={{ replicas }}
  49. {% endif -%}
  50. {% if 'certificate' in openshift.hosted.router and 'contents' in openshift.hosted.router.certificate -%}
  51. --default-cert={{ openshift_master_config_dir }}/openshift-router.pem
  52. {% endif -%}
  53. --namespace={{ openshift.hosted.router.namespace | default('default') }}
  54. {% if openshift.hosted.router.force_subdomain | default(none) is not none %}
  55. --force-subdomain={{ openshift.hosted.router.force_subdomain }}
  56. {% endif %}
  57. --service-account=router
  58. {% if openshift.hosted.router.selector | default(none) is not none -%}
  59. --selector='{{ openshift.hosted.router.selector }}'
  60. {% endif -%}
  61. {% if not openshift.common.version_gte_3_2_or_1_2 | bool -%}
  62. --credentials={{ openshift_master_config_dir }}/openshift-router.kubeconfig
  63. {% endif -%}
  64. {% if openshift.hosted.router.registryurl | default(none) is not none -%}
  65. --images='{{ openshift.hosted.router.registryurl }}'
  66. {% endif -%}
  67. {% if openshift.hosted.router.name | default(none) is not none -%}
  68. {{ openshift.hosted.router.name }}
  69. {% endif -%}
  70. register: openshift_hosted_router_results
  71. changed_when: "'service exists' not in openshift_hosted_router_results.stdout"
  72. failed_when: "openshift_hosted_router_results.rc != 0 and 'service exists' not in openshift_hosted_router_results.stdout and 'deployment_config' not in openshift_hosted_router_results.stderr and 'service' not in openshift_hosted_router_results.stderr"
  73. when: replicas | int > 0