router.yml 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ---
  2. - name: Retrieve list of openshift nodes matching router selector
  3. oc_obj:
  4. state: list
  5. kind: node
  6. namespace: "{{ openshift.hosted.router.namespace | default('default') }}"
  7. selector: "{{ openshift.hosted.router.selector | default(omit) }}"
  8. register: router_nodes
  9. when: openshift.hosted.router.replicas | default(none) is none
  10. - name: set_fact replicas
  11. set_fact:
  12. replicas: "{{ openshift.hosted.router.replicas|default(None) | get_router_replicas(router_nodes) }}"
  13. - block:
  14. - name: Assert that 'certfile', 'keyfile' and 'cafile' keys provided in openshift_hosted_router_certificate
  15. assert:
  16. that:
  17. - "'certfile' in openshift_hosted_router_certificate"
  18. - "'keyfile' in openshift_hosted_router_certificate"
  19. - "'cafile' in openshift_hosted_router_certificate"
  20. msg: "'certfile', 'keyfile' and 'cafile' keys must be specified when supplying the openshift_hosted_router_certificate variable."
  21. - name: Read router certificate and key
  22. become: no
  23. local_action:
  24. module: slurp
  25. src: "{{ item }}"
  26. register: openshift_router_certificate_output
  27. # Defaulting dictionary keys to none to avoid deprecation warnings
  28. # (future fatal errors) during template evaluation. Dictionary keys
  29. # won't be accessed unless openshift_hosted_router_certificate is
  30. # defined and has all keys (certfile, keyfile, cafile) which we
  31. # check above.
  32. with_items:
  33. - "{{ (openshift_hosted_router_certificate | default({'certfile':none})).certfile }}"
  34. - "{{ (openshift_hosted_router_certificate | default({'keyfile':none})).keyfile }}"
  35. - "{{ (openshift_hosted_router_certificate | default({'cafile':none})).cafile }}"
  36. - name: Persist certificate contents
  37. openshift_facts:
  38. role: hosted
  39. openshift_env:
  40. openshift_hosted_router_certificate_contents: "{% for certificate in openshift_router_certificate_output.results -%}{{ certificate.content | b64decode }}{% endfor -%}"
  41. - name: Create PEM certificate
  42. copy:
  43. content: "{{ openshift.hosted.router.certificate.contents }}"
  44. dest: "{{ openshift_master_config_dir }}/openshift-router.pem"
  45. mode: 0600
  46. when: openshift_hosted_router_certificate is defined
  47. - name: Create OpenShift router
  48. oc_adm_router:
  49. name: "{{ openshift.hosted.router.name | default('router') }}"
  50. replicas: "{{ replicas }}"
  51. namespace: "{{ openshift.hosted.router.namespace | default('default') }}"
  52. # This option is not yet implemented
  53. # force_subdomain: "{{ openshift.hosted.router.force_subdomain | default(none) }}"
  54. service_account: router
  55. selector: "{{ openshift.hosted.router.selector | default(none) }}"
  56. images: "{{ openshift.hosted.router.registryurl | default(none) }}"
  57. default_cert: "{{ openshift_hosted_router_certificate is defined | default(false) | ternary(openshift_master_config_dir + '/openshift-router.pem', omit) }}"
  58. # These edits are being specified only to prevent 'changed' on rerun
  59. edits:
  60. - key: spec.strategy.rollingParams.intervalSeconds
  61. value: 1
  62. action: put
  63. - key: spec.strategy.rollingParams.updatePeriodSeconds
  64. value: 1
  65. action: put
  66. - key: spec.strategy.activeDeadlineSeconds
  67. value: 21600
  68. action: put
  69. register: routerout
  70. # This should probably move to module
  71. - name: wait for deploy
  72. pause:
  73. seconds: 30
  74. when: routerout.changed
  75. - name: Ensure router replica count matches desired
  76. oc_scale:
  77. kind: dc
  78. name: "{{ openshift.hosted.router.name | default('router') }}"
  79. namespace: "{{ openshift.hosted.router.namespace | default('default') }}"
  80. replicas: "{{ replicas }}"
  81. when: replicas | int > 0