glusterfs.yml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ---
  2. - name: Get registry DeploymentConfig
  3. oc_obj:
  4. namespace: "{{ openshift_hosted_registry_namespace }}"
  5. state: list
  6. kind: dc
  7. name: "{{ openshift_hosted_registry_name }}"
  8. register: registry_dc
  9. - name: Wait for registry pods
  10. oc_obj:
  11. namespace: "{{ openshift_hosted_registry_namespace }}"
  12. state: list
  13. kind: pod
  14. selector: "{% for label, value in registry_dc.results.results[0].spec.selector.items() %}{{ label }}={{ value }}{% if not loop.last %},{% endif %}{% endfor %}"
  15. register: registry_pods
  16. until:
  17. - "registry_pods.results.results[0]['items'] | count > 0"
  18. # There must be as many matching pods with 'Ready' status True as there are expected replicas
  19. - "registry_pods.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count == openshift_hosted_registry_replicas | int"
  20. delay: 10
  21. retries: "{{ (600 / 10) | int }}"
  22. - name: Determine registry fsGroup
  23. set_fact:
  24. openshift_hosted_registry_fsgroup: "{{ registry_pods.results.results[0]['items'][0].spec.securityContext.fsGroup }}"
  25. - name: Create temp mount directory
  26. command: mktemp -d /tmp/openshift-glusterfs-registry-XXXXXX
  27. register: mktemp
  28. changed_when: False
  29. check_mode: no
  30. - name: Mount registry volume
  31. mount:
  32. state: mounted
  33. fstype: glusterfs
  34. src: "{% if 'glusterfs_registry' in groups %}{% set node = groups.glusterfs_registry[0] %}{% else %}{% set node = groups.glusterfs[0] %}{% endif %}{% if 'glusterfs_hostname' in hostvars[node] %}{{ hostvars[node].glusterfs_hostname }}{% elif 'openshift' in hostvars[node] %}{{ hostvars[node].openshift.node.nodename }}{% else %}{{ node }}{% endif %}:/{{ openshift.hosted.registry.storage.glusterfs.path }}"
  35. name: "{{ mktemp.stdout }}"
  36. - name: Set registry volume permissions
  37. file:
  38. dest: "{{ mktemp.stdout }}"
  39. state: directory
  40. group: "{{ openshift_hosted_registry_fsgroup }}"
  41. mode: "2775"
  42. recurse: True
  43. - block:
  44. - name: Activate registry maintenance mode
  45. oc_env:
  46. namespace: "{{ openshift_hosted_registry_namespace }}"
  47. name: "{{ openshift_hosted_registry_name }}"
  48. env_vars:
  49. - REGISTRY_STORAGE_MAINTENANCE_READONLY_ENABLED: 'true'
  50. - name: Get first registry pod name
  51. set_fact:
  52. registry_pod_name: "{{ registry_pods.results.results[0]['items'][0].metadata.name }}"
  53. - name: Copy current registry contents to new GlusterFS volume
  54. command: "oc rsync {{ registry_pod_name }}:/registry/ {{ mktemp.stdout }}/"
  55. when: openshift.hosted.registry.storage.glusterfs.swapcopy
  56. - name: Swap new GlusterFS registry volume
  57. oc_volume:
  58. namespace: "{{ openshift_hosted_registry_namespace }}"
  59. name: "{{ openshift_hosted_registry_name }}"
  60. vol_name: registry-storage
  61. mount_type: pvc
  62. claim_name: "{{ openshift.hosted.registry.storage.volume.name }}-glusterfs-claim"
  63. - name: Deactivate registry maintenance mode
  64. oc_env:
  65. namespace: "{{ openshift_hosted_registry_namespace }}"
  66. name: "{{ openshift_hosted_registry_name }}"
  67. state: absent
  68. env_vars:
  69. - REGISTRY_STORAGE_MAINTENANCE_READONLY_ENABLED: 'true'
  70. when: openshift.hosted.registry.storage.glusterfs.swap
  71. - name: Unmount registry volume and clean up mount point/fstab
  72. mount:
  73. state: absent
  74. name: "{{ mktemp.stdout }}"