registry.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ---
  2. - name: setup firewall
  3. import_tasks: firewall.yml
  4. vars:
  5. l_openshift_hosted_firewall_enabled: "{{ r_openshift_hosted_registry_firewall_enabled }}"
  6. l_openshift_hosted_use_firewalld: "{{ r_openshift_hosted_registry_use_firewalld }}"
  7. l_openshift_hosted_fw_allow: "{{ r_openshift_hosted_registry_os_firewall_allow }}"
  8. l_openshift_hosted_fw_deny: "{{ r_openshift_hosted_registry_os_firewall_deny }}"
  9. - name: set openshift_hosted facts
  10. set_fact:
  11. # This determines the gluster_ips to use for the registry by looping over the glusterfs_registry group
  12. 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 %}"
  13. - name: Update registry environment variables when pushing via dns
  14. # OPENSHIFT_DEFAULT_REGISTRY is deprecated - keep until 3.11
  15. set_fact:
  16. openshift_hosted_registry_env_vars: "{{ {'OPENSHIFT_DEFAULT_REGISTRY': item,
  17. 'REGISTRY_OPENSHIFT_SERVER_ADDR': item}
  18. | combine(openshift_hosted_registry_env_vars) }}"
  19. with_items:
  20. - "docker-registry.default.svc:5000"
  21. when: openshift_push_via_dns | bool
  22. - name: Update registry proxy settings for dc/docker-registry
  23. set_fact:
  24. openshift_hosted_registry_env_vars: "{{ {'HTTPS_PROXY': (openshift.common.https_proxy | default('')),
  25. 'HTTP_PROXY': (openshift.common.http_proxy | default('')),
  26. 'NO_PROXY': (openshift.common.no_proxy | default(''))}
  27. | combine(openshift_hosted_registry_env_vars) }}"
  28. when: (openshift.common.https_proxy | default(False)) or (openshift.common.http_proxy | default('')) != ''
  29. - name: Create the registry service account
  30. oc_serviceaccount:
  31. name: "{{ openshift_hosted_registry_serviceaccount }}"
  32. namespace: "{{ openshift_hosted_registry_namespace }}"
  33. - name: Grant the registry service account access to the appropriate scc
  34. oc_adm_policy_user:
  35. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  36. namespace: "{{ openshift_hosted_registry_namespace }}"
  37. resource_kind: scc
  38. resource_name: hostnetwork
  39. - name: oc adm policy add-cluster-role-to-user system:registry system:serviceaccount:default:registry
  40. oc_adm_policy_user:
  41. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  42. namespace: "{{ openshift_hosted_registry_namespace }}"
  43. resource_kind: cluster-role
  44. resource_name: system:registry
  45. - name: create the default registry service
  46. oc_service:
  47. namespace: "{{ openshift_hosted_registry_namespace }}"
  48. name: "{{ openshift_hosted_registry_name }}"
  49. ports:
  50. - name: 5000-tcp
  51. port: 5000
  52. protocol: TCP
  53. targetPort: 5000
  54. selector:
  55. docker-registry: default
  56. session_affinity: ClientIP
  57. service_type: ClusterIP
  58. clusterip: '{{ openshift_hosted_registry_clusterip | default(omit) }}'
  59. - include_tasks: secure.yml
  60. run_once: true
  61. when:
  62. - not (openshift_docker_hosted_registry_insecure | default(False)) | bool
  63. - include_tasks: storage/object_storage.yml
  64. when:
  65. - openshift_hosted_registry_storage_kind | default(none) == 'object'
  66. - name: Update openshift_hosted facts for persistent volumes
  67. set_fact:
  68. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(pvc_volume_mounts) }}"
  69. vars:
  70. pvc_volume_mounts:
  71. - name: registry-storage
  72. type: persistentVolumeClaim
  73. claim_name: "{{ openshift_hosted_registry_storage_volume_name }}-claim"
  74. when:
  75. - openshift_hosted_registry_storage_kind | default(none) in ['nfs', 'glusterfs', 'hostpath', 'openstack', 'vsphere']
  76. - include_tasks: storage/glusterfs_endpoints.yml
  77. when:
  78. - openshift_hosted_registry_storage_glusterfs_ips|length > 0
  79. - openshift_hosted_registry_storage_kind | default(none) in ['glusterfs']
  80. - name: Create OpenShift registry
  81. oc_adm_registry:
  82. name: "{{ openshift_hosted_registry_name }}"
  83. namespace: "{{ openshift_hosted_registry_namespace }}"
  84. selector: "{{ openshift_hosted_registry_selector }}"
  85. replicas: "{{ openshift_hosted_registry_replicas }}"
  86. service_account: "{{ openshift_hosted_registry_serviceaccount }}"
  87. images: "{{ openshift_hosted_registry_registryurl }}"
  88. env_vars: "{{ openshift_hosted_registry_env_vars }}"
  89. volume_mounts: "{{ openshift_hosted_registry_volumes }}"
  90. edits: "{{ openshift_hosted_registry_edits }}"
  91. force: "{{ True|bool in openshift_hosted_registry_force }}"
  92. - include_tasks: storage/hostpath.yml
  93. when:
  94. - openshift_hosted_registry_storage_kind | default(none) in ['hostpath']