redeploy-registry-certificates.yml 4.2 KB

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