registry.yml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ---
  2. - name: setup firewall
  3. include: firewall.yml
  4. static: yes
  5. - when: openshift.hosted.registry.replicas | default(none) is none
  6. block:
  7. - name: Retrieve list of openshift nodes matching registry selector
  8. oc_obj:
  9. state: list
  10. kind: node
  11. selector: "{{ openshift.hosted.registry.selector | default(omit) }}"
  12. register: registry_nodes
  13. - name: set_fact l_node_count to number of nodes matching registry selector
  14. set_fact:
  15. l_node_count: "{{ registry_nodes.results.results[0]['items'] | length }}"
  16. # Determine the default number of registry/router replicas to use if no count
  17. # has been specified.
  18. # If no registry nodes defined, the default should be 0.
  19. - name: set_fact l_default_replicas when l_node_count == 0
  20. set_fact:
  21. l_default_replicas: 0
  22. when: l_node_count | int == 0
  23. # If registry nodes are defined and the registry storage kind is
  24. # defined, default should be the number of registry nodes, otherwise
  25. # just 1:
  26. - name: set_fact l_default_replicas when l_node_count > 0
  27. set_fact:
  28. l_default_replicas: "{{ l_node_count if openshift.hosted.registry.storage.kind | default(none) is not none else 1 }}"
  29. when: l_node_count | int > 0
  30. - name: set openshift_hosted facts
  31. set_fact:
  32. openshift_hosted_registry_replicas: "{{ openshift.hosted.registry.replicas | default(l_default_replicas) }}"
  33. openshift_hosted_registry_name: docker-registry
  34. openshift_hosted_registry_serviceaccount: registry
  35. openshift_hosted_registry_namespace: "{{ openshift.hosted.registry.namespace | default('default') }}"
  36. openshift_hosted_registry_selector: "{{ openshift.hosted.registry.selector }}"
  37. openshift_hosted_registry_images: "{{ openshift.hosted.registry.registryurl | default('openshift3/ose-${component}:${version}')}}"
  38. openshift_hosted_registry_volumes: []
  39. openshift_hosted_registry_env_vars: {}
  40. openshift_hosted_registry_edits:
  41. # These edits are being specified only to prevent 'changed' on rerun
  42. - key: spec.strategy.rollingParams
  43. value:
  44. intervalSeconds: 1
  45. maxSurge: "25%"
  46. maxUnavailable: "25%"
  47. timeoutSeconds: 600
  48. updatePeriodSeconds: 1
  49. action: put
  50. openshift_hosted_registry_force:
  51. - False
  52. - name: Update registry environment variables when pushing via dns
  53. set_fact:
  54. openshift_hosted_registry_env_vars: "{{ openshift_hosted_registry_env_vars | combine({'OPENSHIFT_DEFAULT_REGISTRY':'docker-registry.default.svc:5000'}) }}"
  55. when: openshift_push_via_dns | default(false) | bool
  56. - name: Update registry proxy settings for dc/docker-registry
  57. set_fact:
  58. openshift_hosted_registry_env_vars: "{{ {'HTTPS_PROXY': (openshift.common.https_proxy | default('')),
  59. 'HTTP_PROXY': (openshift.common.http_proxy | default('')),
  60. 'NO_PROXY': (openshift.common.no_proxy | default(''))}
  61. | combine(openshift_hosted_registry_env_vars) }}"
  62. when: (openshift.common.https_proxy | default(False)) or (openshift.common.http_proxy | default('')) != ''
  63. - name: Create the registry service account
  64. oc_serviceaccount:
  65. name: "{{ openshift_hosted_registry_serviceaccount }}"
  66. namespace: "{{ openshift_hosted_registry_namespace }}"
  67. - name: Grant the registry service account access to the appropriate scc
  68. oc_adm_policy_user:
  69. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  70. namespace: "{{ openshift_hosted_registry_namespace }}"
  71. resource_kind: scc
  72. resource_name: hostnetwork
  73. - name: oc adm policy add-cluster-role-to-user system:registry system:serviceaccount:default:registry
  74. oc_adm_policy_user:
  75. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  76. namespace: "{{ openshift_hosted_registry_namespace }}"
  77. resource_kind: cluster-role
  78. resource_name: system:registry
  79. - name: create the default registry service
  80. oc_service:
  81. namespace: "{{ openshift_hosted_registry_namespace }}"
  82. name: "{{ openshift_hosted_registry_name }}"
  83. ports:
  84. - name: 5000-tcp
  85. port: 5000
  86. protocol: TCP
  87. targetPort: 5000
  88. selector:
  89. docker-registry: default
  90. session_affinity: ClientIP
  91. service_type: ClusterIP
  92. - include: secure.yml
  93. static: no
  94. run_once: true
  95. when:
  96. - not (openshift.docker.hosted_registry_insecure | default(false) | bool)
  97. - include: storage/object_storage.yml
  98. static: no
  99. when:
  100. - openshift.hosted.registry.storage.kind | default(none) == 'object'
  101. - name: Update openshift_hosted facts for persistent volumes
  102. set_fact:
  103. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(pvc_volume_mounts) }}"
  104. vars:
  105. pvc_volume_mounts:
  106. - name: registry-storage
  107. type: persistentVolumeClaim
  108. claim_name: "{{ openshift.hosted.registry.storage.volume.name }}-claim"
  109. when:
  110. - openshift.hosted.registry.storage.kind | default(none) in ['nfs', 'openstack', 'glusterfs']
  111. - name: Create OpenShift registry
  112. oc_adm_registry:
  113. name: "{{ openshift_hosted_registry_name }}"
  114. namespace: "{{ openshift_hosted_registry_namespace }}"
  115. selector: "{{ openshift_hosted_registry_selector }}"
  116. replicas: "{{ openshift_hosted_registry_replicas }}"
  117. service_account: "{{ openshift_hosted_registry_serviceaccount }}"
  118. images: "{{ openshift_hosted_registry_images }}"
  119. env_vars: "{{ openshift_hosted_registry_env_vars }}"
  120. volume_mounts: "{{ openshift_hosted_registry_volumes }}"
  121. edits: "{{ openshift_hosted_registry_edits }}"
  122. force: "{{ True|bool in openshift_hosted_registry_force }}"
  123. - when: openshift_hosted_registry_wait | bool
  124. block:
  125. - name: Ensure OpenShift registry correctly rolls out (best-effort today)
  126. command: |
  127. oc rollout status deploymentconfig {{ openshift_hosted_registry_name }} \
  128. --namespace {{ openshift_hosted_registry_namespace }} \
  129. --config {{ openshift.common.config_base }}/master/admin.kubeconfig
  130. async: 600
  131. poll: 15
  132. failed_when: false
  133. - name: Determine the latest version of the OpenShift registry deployment
  134. command: |
  135. {{ openshift.common.client_binary }} get deploymentconfig {{ openshift_hosted_registry_name }} \
  136. --namespace {{ openshift_hosted_registry_namespace }} \
  137. --config {{ openshift.common.config_base }}/master/admin.kubeconfig \
  138. -o jsonpath='{ .status.latestVersion }'
  139. register: openshift_hosted_registry_latest_version
  140. - name: Sanity-check that the OpenShift registry rolled out correctly
  141. command: |
  142. {{ openshift.common.client_binary }} get replicationcontroller {{ openshift_hosted_registry_name }}-{{ openshift_hosted_registry_latest_version.stdout }} \
  143. --namespace {{ openshift_hosted_registry_namespace }} \
  144. --config {{ openshift.common.config_base }}/master/admin.kubeconfig \
  145. -o jsonpath='{ .metadata.annotations.openshift\.io/deployment\.phase }'
  146. register: openshift_hosted_registry_rc_phase
  147. until: "'Running' not in openshift_hosted_registry_rc_phase.stdout"
  148. delay: 15
  149. retries: 40
  150. failed_when: "'Failed' in openshift_hosted_registry_rc_phase.stdout"
  151. - include: storage/glusterfs.yml
  152. when:
  153. - openshift.hosted.registry.storage.kind | default(none) == 'glusterfs' or openshift.hosted.registry.storage.glusterfs.swap