registry.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ---
  2. - block:
  3. - name: Retrieve list of openshift nodes matching registry selector
  4. oc_obj:
  5. state: list
  6. kind: node
  7. selector: "{{ openshift.hosted.registry.selector | default(omit) }}"
  8. register: registry_nodes
  9. - name: set_fact l_node_count to number of nodes matching registry selector
  10. set_fact:
  11. l_node_count: "{{ registry_nodes.results.results[0]['items'] | length }}"
  12. # Determine the default number of registry/router replicas to use if no count
  13. # has been specified.
  14. # If no registry nodes defined, the default should be 0.
  15. - name: set_fact l_default_replicas when l_node_count == 0
  16. set_fact:
  17. l_default_replicas: 0
  18. when: l_node_count | int == 0
  19. # If registry nodes are defined and the registry storage kind is
  20. # defined, default should be the number of registry nodes, otherwise
  21. # just 1:
  22. - name: set_fact l_default_replicas when l_node_count > 0
  23. set_fact:
  24. l_default_replicas: "{{ l_node_count if openshift.hosted.registry.storage.kind | default(none) is not none else 1 }}"
  25. when: l_node_count | int > 0
  26. when: openshift.hosted.registry.replicas | default(none) is none
  27. - name: set openshift_hosted facts
  28. set_fact:
  29. openshift_hosted_registry_replicas: "{{ openshift.hosted.registry.replicas | default(l_default_replicas) }}"
  30. openshift_hosted_registry_name: docker-registry
  31. openshift_hosted_registry_serviceaccount: registry
  32. openshift_hosted_registry_namespace: "{{ openshift.hosted.registry.namespace | default('default') }}"
  33. openshift_hosted_registry_selector: "{{ openshift.hosted.registry.selector }}"
  34. openshift_hosted_registry_images: "{{ openshift.hosted.registry.registryurl | default('openshift3/ose-${component}:${version}')}}"
  35. openshift_hosted_registry_volumes: []
  36. openshift_hosted_registry_env_vars: {}
  37. openshift_hosted_registry_routecertificates: "{{ ('routecertificates' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routecertificates, {}) }}"
  38. openshift_hosted_registry_routehost: "{{ ('routehost' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routehost, False) }}"
  39. openshift_hosted_registry_routetermination: "{{ ('routetermination' in openshift.hosted.registry.keys()) | ternary(openshift.hosted.registry.routetermination, 'passthrough') }}"
  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: Create the registry service account
  53. oc_serviceaccount:
  54. name: "{{ openshift_hosted_registry_serviceaccount }}"
  55. namespace: "{{ openshift_hosted_registry_namespace }}"
  56. - name: Grant the registry service account access to the appropriate scc
  57. oc_adm_policy_user:
  58. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  59. namespace: "{{ openshift_hosted_registry_namespace }}"
  60. resource_kind: scc
  61. resource_name: hostnetwork
  62. - name: oc adm policy add-cluster-role-to-user system:registry system:serviceaccount:default:registry
  63. oc_adm_policy_user:
  64. user: "system:serviceaccount:{{ openshift_hosted_registry_namespace }}:{{ openshift_hosted_registry_serviceaccount }}"
  65. namespace: "{{ openshift_hosted_registry_namespace }}"
  66. resource_kind: cluster-role
  67. resource_name: system:registry
  68. - name: create the default registry service
  69. oc_service:
  70. namespace: "{{ openshift_hosted_registry_namespace }}"
  71. name: "{{ openshift_hosted_registry_name }}"
  72. ports:
  73. - name: 5000-tcp
  74. port: 5000
  75. protocol: TCP
  76. targetPort: 5000
  77. selector:
  78. docker-registry: default
  79. session_affinity: ClientIP
  80. service_type: ClusterIP
  81. - include: secure.yml
  82. static: no
  83. run_once: true
  84. when:
  85. - not (openshift.docker.hosted_registry_insecure | default(false) | bool)
  86. - include: storage/object_storage.yml
  87. static: no
  88. when:
  89. - openshift.hosted.registry.storage.kind | default(none) == 'object'
  90. - name: Update openshift_hosted facts for persistent volumes
  91. set_fact:
  92. openshift_hosted_registry_volumes: "{{ openshift_hosted_registry_volumes | union(pvc_volume_mounts) }}"
  93. vars:
  94. pvc_volume_mounts:
  95. - name: registry-storage
  96. type: persistentVolumeClaim
  97. claim_name: "{{ openshift.hosted.registry.storage.volume.name }}-claim"
  98. when:
  99. - openshift.hosted.registry.storage.kind | default(none) in ['nfs', 'openstack', 'glusterfs']
  100. - name: Create OpenShift registry
  101. oc_adm_registry:
  102. name: "{{ openshift_hosted_registry_name }}"
  103. namespace: "{{ openshift_hosted_registry_namespace }}"
  104. selector: "{{ openshift_hosted_registry_selector }}"
  105. replicas: "{{ openshift_hosted_registry_replicas }}"
  106. service_account: "{{ openshift_hosted_registry_serviceaccount }}"
  107. images: "{{ openshift_hosted_registry_images }}"
  108. env_vars: "{{ openshift_hosted_registry_env_vars }}"
  109. volume_mounts: "{{ openshift_hosted_registry_volumes }}"
  110. edits: "{{ openshift_hosted_registry_edits }}"
  111. force: "{{ True|bool in openshift_hosted_registry_force }}"
  112. - include: storage/glusterfs.yml
  113. when:
  114. - openshift.hosted.registry.storage.kind | default(none) == 'glusterfs' or openshift.hosted.registry.storage.glusterfs.swap