router.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ---
  2. - name: setup firewall
  3. include: firewall.yml
  4. static: yes
  5. - name: Retrieve list of openshift nodes matching router selector
  6. oc_obj:
  7. state: list
  8. kind: node
  9. namespace: "{{ openshift.hosted.router.namespace | default('default') }}"
  10. selector: "{{ openshift.hosted.router.selector | default(omit) }}"
  11. register: router_nodes
  12. when: openshift.hosted.router.replicas | default(none) is none
  13. - name: set_fact replicas
  14. set_fact:
  15. replicas: "{{ openshift.hosted.router.replicas|default(None) | get_router_replicas(router_nodes) }}"
  16. openshift_hosted_router_selector: "{{ openshift.hosted.router.selector | default(None) }}"
  17. openshift_hosted_router_image: "{{ openshift.hosted.router.registryurl }}"
  18. # This is for when we desire a cluster signed cert
  19. # The certificate is generated and placed in master_config_dir/
  20. - block:
  21. - name: generate a default wildcard router certificate
  22. oc_adm_ca_server_cert:
  23. signer_cert: "{{ openshift_master_config_dir }}/ca.crt"
  24. signer_key: "{{ openshift_master_config_dir }}/ca.key"
  25. signer_serial: "{{ openshift_master_config_dir }}/ca.serial.txt"
  26. hostnames:
  27. - "{{ openshift_master_default_subdomain | default('router.default.svc.cluster.local') }}"
  28. - "*.{{ openshift_master_default_subdomain | default('router.default.svc.cluster.local') }}"
  29. cert: "{{ ('/etc/origin/master/' ~ (item.certificate.certfile | basename)) if 'certfile' in item.certificate else ((openshift_master_config_dir) ~ '/openshift-router.crt') }}"
  30. key: "{{ ('/etc/origin/master/' ~ (item.certificate.keyfile | basename)) if 'keyfile' in item.certificate else ((openshift_master_config_dir) ~ '/openshift-router.key') }}"
  31. with_items: "{{ openshift_hosted_routers }}"
  32. - name: set the openshift_hosted_router_certificate
  33. set_fact:
  34. openshift_hosted_router_certificate:
  35. certfile: "{{ openshift_master_config_dir ~ '/openshift-router.crt' }}"
  36. keyfile: "{{ openshift_master_config_dir ~ '/openshift-router.key' }}"
  37. cafile: "{{ openshift_master_config_dir ~ '/ca.crt' }}"
  38. # End Block
  39. when: ( openshift_hosted_router_create_certificate | bool ) and openshift_hosted_router_certificate == {}
  40. - name: Get the certificate contents for router
  41. copy:
  42. backup: True
  43. dest: "/etc/origin/master/{{ item | basename }}"
  44. src: "{{ item }}"
  45. with_items: "{{ openshift_hosted_routers | oo_collect(attribute='certificate') |
  46. oo_select_keys_from_list(['keyfile', 'certfile', 'cafile']) }}"
  47. when: not openshift_hosted_router_create_certificate | bool
  48. - name: Create the router service account(s)
  49. oc_serviceaccount:
  50. name: "{{ item.serviceaccount }}"
  51. namespace: "{{ item.namespace }}"
  52. state: present
  53. with_items: "{{ openshift_hosted_routers }}"
  54. - name: Grant the router service account(s) access to the appropriate scc
  55. oc_adm_policy_user:
  56. user: "system:serviceaccount:{{ item.namespace }}:{{ item.serviceaccount }}"
  57. namespace: "{{ item.namespace }}"
  58. resource_kind: scc
  59. resource_name: hostnetwork
  60. with_items: "{{ openshift_hosted_routers }}"
  61. - name: Set additional permissions for router service account
  62. oc_adm_policy_user:
  63. user: "system:serviceaccount:{{ item.namespace }}:{{ item.serviceaccount }}"
  64. namespace: "{{ item.namespace }}"
  65. resource_kind: cluster-role
  66. resource_name: cluster-reader
  67. when: item.namespace == 'default'
  68. with_items: "{{ openshift_hosted_routers }}"
  69. - name: Create OpenShift router
  70. oc_adm_router:
  71. name: "{{ item.name }}"
  72. replicas: "{{ item.replicas }}"
  73. namespace: "{{ item.namespace | default('default') }}"
  74. # This option is not yet implemented
  75. # force_subdomain: "{{ openshift.hosted.router.force_subdomain | default(none) }}"
  76. service_account: "{{ item.serviceaccount | default('router') }}"
  77. selector: "{{ item.selector | default(none) }}"
  78. images: "{{ item.images | default(omit) }}"
  79. cert_file: "{{ ('/etc/origin/master/' ~ (item.certificate.certfile | basename)) if 'certfile' in item.certificate else omit }}"
  80. key_file: "{{ ('/etc/origin/master/' ~ (item.certificate.keyfile | basename)) if 'keyfile' in item.certificate else omit }}"
  81. cacert_file: "{{ ('/etc/origin/master/' ~ (item.certificate.cafile | basename)) if 'cafile' in item.certificate else omit }}"
  82. edits: "{{ openshift_hosted_router_edits | union(item.edits) }}"
  83. ports: "{{ item.ports }}"
  84. stats_port: "{{ item.stats_port }}"
  85. with_items: "{{ openshift_hosted_routers }}"
  86. - name: Ensure OpenShift router correctly rolls out (best-effort today)
  87. command: |
  88. {{ openshift.common.client_binary }} rollout status deploymentconfig {{ item.name }} \
  89. --namespace {{ item.namespace | default('default') }} \
  90. --config {{ openshift.common.config_base }}/master/admin.kubeconfig
  91. async: 600
  92. poll: 15
  93. with_items: "{{ openshift_hosted_routers }}"
  94. failed_when: false
  95. - name: Determine the latest version of the OpenShift router deployment
  96. command: |
  97. {{ openshift.common.client_binary }} get deploymentconfig {{ item.name }} \
  98. --namespace {{ item.namespace }} \
  99. --config {{ openshift.common.config_base }}/master/admin.kubeconfig \
  100. -o jsonpath='{ .status.latestVersion }'
  101. register: openshift_hosted_routers_latest_version
  102. with_items: "{{ openshift_hosted_routers }}"
  103. - name: Poll for OpenShift router deployment success
  104. command: |
  105. {{ openshift.common.client_binary }} get replicationcontroller {{ item.0.name }}-{{ item.1.stdout }} \
  106. --namespace {{ item.0.namespace }} \
  107. --config {{ openshift.common.config_base }}/master/admin.kubeconfig \
  108. -o jsonpath='{ .metadata.annotations.openshift\.io/deployment\.phase }'
  109. register: openshift_hosted_router_rc_phase
  110. until: "'Running' not in openshift_hosted_router_rc_phase.stdout"
  111. delay: 15
  112. retries: 40
  113. failed_when: "'Failed' in openshift_hosted_router_rc_phase.stdout"
  114. with_together:
  115. - "{{ openshift_hosted_routers }}"
  116. - "{{ openshift_hosted_routers_latest_version.results }}"