redeploy-registry-certificates.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ---
  2. - name: Update registry certificates
  3. hosts: oo_first_master
  4. vars:
  5. roles:
  6. - lib_openshift
  7. tasks:
  8. - name: Create temp directory for kubeconfig
  9. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  10. register: mktemp
  11. changed_when: false
  12. - name: Copy admin client config(s)
  13. command: >
  14. cp {{ openshift.common.config_base }}/master//admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  15. changed_when: false
  16. - name: Determine if docker-registry exists
  17. command: >
  18. {{ openshift_client_binary }} get dc/docker-registry -o json
  19. --config={{ mktemp.stdout }}/admin.kubeconfig
  20. -n default
  21. register: l_docker_registry_dc
  22. failed_when: false
  23. changed_when: false
  24. - set_fact:
  25. docker_registry_env_vars: "{{ ((l_docker_registry_dc.stdout | from_json)['spec']['template']['spec']['containers'][0]['env']
  26. | lib_utils_oo_collect('name'))
  27. | default([]) }}"
  28. docker_registry_secrets: "{{ ((l_docker_registry_dc.stdout | from_json)['spec']['template']['spec']['volumes']
  29. | lib_utils_oo_collect('secret')
  30. | lib_utils_oo_collect('secretName'))
  31. | default([]) }}"
  32. changed_when: false
  33. when: l_docker_registry_dc.rc == 0
  34. # Replace dc/docker-registry environment variable certificate data if set.
  35. - name: Update docker-registry environment variables
  36. shell: >
  37. {{ openshift_client_binary }} env dc/docker-registry
  38. OPENSHIFT_CA_DATA="$(cat /etc/origin/master/ca.crt)"
  39. OPENSHIFT_CERT_DATA="$(cat /etc/origin/master/openshift-registry.crt)"
  40. OPENSHIFT_KEY_DATA="$(cat /etc/origin/master/openshift-registry.key)"
  41. --config={{ mktemp.stdout }}/admin.kubeconfig
  42. -n default
  43. when: l_docker_registry_dc.rc == 0 and 'OPENSHIFT_CA_DATA' in docker_registry_env_vars and 'OPENSHIFT_CERT_DATA' in docker_registry_env_vars and 'OPENSHIFT_KEY_DATA' in docker_registry_env_vars
  44. # Replace dc/docker-registry certificate secret contents if set.
  45. - block:
  46. - name: Retrieve registry service IP
  47. oc_service:
  48. namespace: default
  49. name: docker-registry
  50. state: list
  51. register: docker_registry_service_ip
  52. changed_when: false
  53. - set_fact:
  54. docker_registry_route_hostname: "{{ 'docker-registry-default.' ~ (openshift.master.default_subdomain | default('router.default.svc.cluster.local', true)) }}"
  55. changed_when: false
  56. - name: Generate registry certificate
  57. command: >
  58. {{ openshift_client_binary }} adm ca create-server-cert
  59. --signer-cert={{ openshift.common.config_base }}/master/ca.crt
  60. --signer-key={{ openshift.common.config_base }}/master/ca.key
  61. --signer-serial={{ openshift.common.config_base }}/master/ca.serial.txt
  62. --config={{ mktemp.stdout }}/admin.kubeconfig
  63. --hostnames="{{ docker_registry_service_ip.results.clusterip }},docker-registry.default.svc,docker-registry.default.svc.cluster.local,{{ docker_registry_route_hostname }}"
  64. --cert={{ openshift.common.config_base }}/master/registry.crt
  65. --key={{ openshift.common.config_base }}/master/registry.key
  66. --expire-days={{ openshift_hosted_registry_cert_expire_days | default(730) }}
  67. - name: Update registry certificates secret
  68. oc_secret:
  69. kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
  70. name: registry-certificates
  71. namespace: default
  72. state: present
  73. files:
  74. - name: registry.crt
  75. path: "{{ openshift.common.config_base }}/master/registry.crt"
  76. - name: registry.key
  77. path: "{{ openshift.common.config_base }}/master/registry.key"
  78. run_once: true
  79. when: l_docker_registry_dc.rc == 0 and 'registry-certificates' in docker_registry_secrets and 'REGISTRY_HTTP_TLS_CERTIFICATE' in docker_registry_env_vars and 'REGISTRY_HTTP_TLS_KEY' in docker_registry_env_vars
  80. - name: Redeploy docker registry
  81. command: >
  82. {{ openshift_client_binary }} deploy dc/docker-registry
  83. --latest
  84. --config={{ mktemp.stdout }}/admin.kubeconfig
  85. -n default
  86. - name: Delete temp directory
  87. file:
  88. name: "{{ mktemp.stdout }}"
  89. state: absent
  90. changed_when: False