secure.yml 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ---
  2. - name: Set fact docker_registry_route_hostname
  3. set_fact:
  4. docker_registry_route_hostname: "{{ 'docker-registry-default.' ~ (openshift_master_default_subdomain | default('router.default.svc.cluster.local', true)) }}"
  5. run_once: true
  6. - debug: var=openshift_hosted_registry_routecertificates
  7. - name: Get the certificate contents for registry
  8. copy:
  9. backup: True
  10. dest: "/etc/origin/master/named_certificates/{{ item.value | basename }}"
  11. src: "{{ item.value }}"
  12. when: item.key in ['certfile', 'keyfile', 'cafile'] and item.value is not None
  13. with_dict: "{{ openshift_hosted_registry_routecertificates }}"
  14. when: openshift_hosted_registry_routecertificates
  15. - debug: var=openshift_hosted_registry_route_termination
  16. - name: Create passthrough route for docker-registry
  17. oc_route:
  18. name: docker-registry
  19. namespace: "{{ openshift_hosted_registry_namespace }}"
  20. service_name: docker-registry
  21. tls_termination: "{{ openshift_hosted_registry_routetermination }}"
  22. host: "{{ openshift_hosted_registry_routehost | default(docker_registry_route_hostname) }}"
  23. cert_path: "{{ ('certfile' in openshift_hosted_registry_routecertificates) | ternary('/etc/origin/master/named_certificates/' ~ (openshift_hosted_registry_routecertificates.certfile | basename), omit) }}"
  24. key_path: "{{ ('keyfile' in openshift_hosted_registry_routecertificates) | ternary('/etc/origin/master/named_certificates/' ~ (openshift_hosted_registry_routecertificates.keyfile | basename), omit) }}"
  25. cacert_path: "{{ ('cafile' in openshift_hosted_registry_routecertificates) | ternary('/etc/origin/master/named_certificates/' ~ (openshift_hosted_registry_routecertificates.cafile | basename), omit) }}"
  26. dest_cacert_path: "{{ (openshift_hosted_registry_routetermination == 'reencrypt') | ternary('/etc/origin/master/ca.crt', omit) }}"
  27. run_once: true
  28. - name: Retrieve registry service IP
  29. oc_service:
  30. namespace: "{{ openshift_hosted_registry_namespace }}"
  31. name: docker-registry
  32. state: list
  33. register: docker_registry_service_ip
  34. run_once: true
  35. - name: Create registry certificates
  36. oc_adm_ca_server_cert:
  37. signer_cert: "{{ openshift_master_config_dir }}/ca.crt"
  38. signer_key: "{{ openshift_master_config_dir }}/ca.key"
  39. signer_serial: "{{ openshift_master_config_dir }}/ca.serial.txt"
  40. hostnames:
  41. - "{{ docker_registry_service_ip.results.clusterip }}"
  42. - docker-registry.default.svc.cluster.local
  43. - "{{ docker_registry_route_hostname }}"
  44. cert: "{{ openshift_master_config_dir }}/registry.crt"
  45. key: "{{ openshift_master_config_dir }}/registry.key"
  46. register: server_cert_out
  47. - name: Create the secret for the registry certificates
  48. oc_secret:
  49. name: registry-certificates
  50. namespace: "{{ openshift_hosted_registry_namespace }}"
  51. files:
  52. - name: registry.crt
  53. path: "{{ openshift_master_config_dir }}/registry.crt"
  54. - name: registry.key
  55. path: "{{ openshift_master_config_dir }}/registry.key"
  56. register: create_registry_certificates_secret_out
  57. - name: Add the secret to the registry's pod service accounts
  58. oc_serviceaccount_secret:
  59. service_account: "{{ item }}"
  60. secret: registry-certificates
  61. namespace: "{{ openshift_hosted_registry_namespace }}"
  62. with_items:
  63. - registry
  64. - default
  65. - name: Set facts for secure registry
  66. set_fact:
  67. registry_secure_volume_mounts:
  68. - name: registry-certificates
  69. path: /etc/secrets
  70. type: secret
  71. secret_name: registry-certificates
  72. registry_secure_env_vars:
  73. REGISTRY_HTTP_TLS_CERTIFICATE: /etc/secrets/registry.crt
  74. REGISTRY_HTTP_TLS_KEY: /etc/secrets/registry.key
  75. registry_secure_edits:
  76. - key: spec.template.spec.containers[0].livenessProbe.httpGet.scheme
  77. value: HTTPS
  78. action: put
  79. - key: spec.template.spec.containers[0].readinessProbe.httpGet.scheme
  80. value: HTTPS
  81. action: put
  82. - name: Update openshift_hosted facts with secure registry variables
  83. set_fact:
  84. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(registry_secure_volume_mounts) }}"
  85. openshift_hosted_registry_env_vars: "{{ openshift_hosted_registry_env_vars | combine(registry_secure_env_vars) }}"
  86. openshift_hosted_registry_edits: "{{ openshift_hosted_registry_edits | union(registry_secure_edits) }}"
  87. openshift_hosted_registry_force: "{{ openshift_hosted_registry_force | union([server_cert_out.changed]) | union([create_registry_certificates_secret_out.changed]) }}"