registry.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ---
  2. - name: Create temp directory for doing work in
  3. command: mktemp -d /tmp/openshift-hosted-ansible-XXXXXX
  4. register: mktempHosted
  5. changed_when: False
  6. check_mode: no
  7. - name: setup firewall
  8. include: firewall.yml
  9. vars:
  10. l_openshift_hosted_firewall_enabled: "{{ r_openshift_hosted_registry_firewall_enabled }}"
  11. l_openshift_hosted_use_firewalld: "{{ r_openshift_hosted_registry_use_firewalld }}"
  12. l_openshift_hosted_fw_allow: "{{ r_openshift_hosted_registry_os_firewall_allow }}"
  13. l_openshift_hosted_fw_deny: "{{ r_openshift_hosted_registry_os_firewall_deny }}"
  14. - when: openshift.hosted.registry.replicas | default(none) is none
  15. block:
  16. - name: Retrieve list of openshift nodes matching registry selector
  17. oc_obj:
  18. state: list
  19. kind: node
  20. selector: "{{ openshift.hosted.registry.selector | default(omit) }}"
  21. register: registry_nodes
  22. - name: set_fact l_node_count to number of nodes matching registry selector
  23. set_fact:
  24. l_node_count: "{{ registry_nodes.results.results[0]['items'] | length }}"
  25. # Determine the default number of registry/router replicas to use if no count
  26. # has been specified.
  27. # If no registry nodes defined, the default should be 0.
  28. - name: set_fact l_default_replicas when l_node_count == 0
  29. set_fact:
  30. l_default_replicas: 0
  31. when: l_node_count | int == 0
  32. # If registry nodes are defined and the registry storage kind is
  33. # defined, default should be the number of registry nodes, otherwise
  34. # just 1:
  35. - name: set_fact l_default_replicas when l_node_count > 0
  36. set_fact:
  37. l_default_replicas: "{{ l_node_count if openshift.hosted.registry.storage.kind | default(none) is not none else 1 }}"
  38. when: l_node_count | int > 0
  39. - name: set openshift_hosted facts
  40. set_fact:
  41. openshift_hosted_registry_replicas: "{{ openshift.hosted.registry.replicas | default(l_default_replicas) }}"
  42. openshift_hosted_registry_namespace: "{{ openshift.hosted.registry.namespace | default('default') }}"
  43. openshift_hosted_registry_selector: "{{ openshift.hosted.registry.selector }}"
  44. openshift_hosted_registry_images: "{{ openshift.hosted.registry.registryurl | default('openshift3/ose-${component}:${version}')}}"
  45. openshift_hosted_registry_storage_glusterfs_ips: "{%- set gluster_ips = [] %}{% if groups.glusterfs_registry is defined %}{% for node in groups.glusterfs_registry %}{%- set _ = gluster_ips.append(hostvars[node].glusterfs_ip | default(hostvars[node].openshift.common.ip)) %}{% endfor %}{{ gluster_ips }}{% elif groups.glusterfs is defined %}{% for node in groups.glusterfs %}{%- set _ = gluster_ips.append(hostvars[node].glusterfs_ip | default(hostvars[node].openshift.common.ip)) %}{% endfor %}{{ gluster_ips }}{% else %}{{ openshift.hosted.registry.storage.glusterfs.ips }}{% endif %}"
  46. - name: Update registry environment variables when pushing via dns
  47. set_fact:
  48. openshift_hosted_registry_env_vars: "{{ openshift_hosted_registry_env_vars | combine({'OPENSHIFT_DEFAULT_REGISTRY':'docker-registry.default.svc:5000'}) }}"
  49. when: openshift_push_via_dns | bool
  50. - name: Update registry proxy settings for dc/docker-registry
  51. set_fact:
  52. openshift_hosted_registry_env_vars: "{{ {'HTTPS_PROXY': (openshift.common.https_proxy | default('')),
  53. 'HTTP_PROXY': (openshift.common.http_proxy | default('')),
  54. 'NO_PROXY': (openshift.common.no_proxy | default(''))}
  55. | combine(openshift_hosted_registry_env_vars) }}"
  56. when: (openshift.common.https_proxy | default(False)) or (openshift.common.http_proxy | default('')) != ''
  57. - name: Create the registry service account
  58. oc_serviceaccount:
  59. name: "{{ openshift_hosted_registry_serviceaccount }}"
  60. namespace: "{{ openshift_hosted_registry_namespace }}"
  61. - name: Grant the registry service account access to the appropriate scc
  62. oc_adm_policy_user:
  63. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  64. namespace: "{{ openshift_hosted_registry_namespace }}"
  65. resource_kind: scc
  66. resource_name: hostnetwork
  67. - name: oc adm policy add-cluster-role-to-user system:registry system:serviceaccount:default:registry
  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: cluster-role
  72. resource_name: system:registry
  73. - name: create the default registry service
  74. oc_service:
  75. namespace: "{{ openshift_hosted_registry_namespace }}"
  76. name: "{{ openshift_hosted_registry_name }}"
  77. ports:
  78. - name: 5000-tcp
  79. port: 5000
  80. protocol: TCP
  81. targetPort: 5000
  82. selector:
  83. docker-registry: default
  84. session_affinity: ClientIP
  85. service_type: ClusterIP
  86. clusterip: '{{ openshift_hosted_registry_clusterip | default(omit) }}'
  87. - include: secure.yml
  88. static: no
  89. run_once: true
  90. when:
  91. - not (openshift_docker_hosted_registry_insecure | default(False)) | bool
  92. - include: storage/object_storage.yml
  93. static: no
  94. when:
  95. - openshift.hosted.registry.storage.kind | default(none) == 'object'
  96. - name: Update openshift_hosted facts for persistent volumes
  97. set_fact:
  98. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(pvc_volume_mounts) }}"
  99. vars:
  100. pvc_volume_mounts:
  101. - name: registry-storage
  102. type: persistentVolumeClaim
  103. claim_name: "{{ openshift.hosted.registry.storage.volume.name }}-claim"
  104. when:
  105. - openshift.hosted.registry.storage.kind | default(none) in ['nfs', 'openstack', 'glusterfs']
  106. - include: storage/glusterfs_endpoints.yml
  107. when:
  108. - openshift_hosted_registry_storage_glusterfs_ips|length > 0
  109. - openshift.hosted.registry.storage.kind | default(none) in ['glusterfs']
  110. - name: Create OpenShift registry
  111. oc_adm_registry:
  112. name: "{{ openshift_hosted_registry_name }}"
  113. namespace: "{{ openshift_hosted_registry_namespace }}"
  114. selector: "{{ openshift_hosted_registry_selector }}"
  115. replicas: "{{ openshift_hosted_registry_replicas }}"
  116. service_account: "{{ openshift_hosted_registry_serviceaccount }}"
  117. images: "{{ openshift_hosted_registry_images }}"
  118. env_vars: "{{ openshift_hosted_registry_env_vars }}"
  119. volume_mounts: "{{ openshift_hosted_registry_volumes }}"
  120. edits: "{{ openshift_hosted_registry_edits }}"
  121. force: "{{ True|bool in openshift_hosted_registry_force }}"
  122. - name: setup registry list
  123. set_fact:
  124. r_openshift_hosted_registry_list:
  125. - name: "{{ openshift_hosted_registry_name }}"
  126. namespace: "{{ openshift_hosted_registry_namespace }}"
  127. - name: Wait for pod (Registry)
  128. include: wait_for_pod.yml
  129. vars:
  130. l_openshift_hosted_wait_for_pod: "{{ openshift_hosted_registry_wait }}"
  131. l_openshift_hosted_wfp_items: "{{ r_openshift_hosted_registry_list }}"
  132. - include: storage/glusterfs.yml
  133. when:
  134. - openshift.hosted.registry.storage.kind | default(none) == 'glusterfs' or openshift.hosted.registry.storage.glusterfs.swap
  135. - name: Delete temp directory
  136. file:
  137. name: "{{ mktempHosted.stdout }}"
  138. state: absent
  139. changed_when: False
  140. check_mode: no