glusterfs_common.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ---
  2. - name: Verify target namespace exists
  3. oc_project:
  4. state: present
  5. name: "{{ glusterfs_namespace }}"
  6. when: glusterfs_is_native or glusterfs_heketi_is_native
  7. - name: Delete pre-existing heketi resources
  8. oc_obj:
  9. namespace: "{{ glusterfs_namespace }}"
  10. kind: "{{ item.kind }}"
  11. name: "{{ item.name | default(omit) }}"
  12. selector: "{{ item.selector | default(omit) }}"
  13. state: absent
  14. with_items:
  15. - kind: "template,route,service,dc,jobs,secret"
  16. selector: "deploy-heketi"
  17. - kind: "svc"
  18. name: "heketi-storage-endpoints"
  19. - kind: "secret"
  20. name: "heketi-{{ glusterfs_name }}-topology-secret"
  21. - kind: "template,route,service,dc"
  22. name: "heketi-{{ glusterfs_name }}"
  23. - kind: "svc"
  24. name: "heketi-db-{{ glusterfs_name }}-endpoints"
  25. - kind: "sa"
  26. name: "heketi-{{ glusterfs_name }}-service-account"
  27. - kind: "secret"
  28. name: "heketi-{{ glusterfs_name }}-user-secret"
  29. failed_when: False
  30. when: glusterfs_heketi_wipe
  31. - name: Wait for deploy-heketi pods to terminate
  32. oc_obj:
  33. namespace: "{{ glusterfs_namespace }}"
  34. kind: pod
  35. state: list
  36. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  37. register: heketi_pod
  38. until: "heketi_pod.results.results[0]['items'] | count == 0"
  39. delay: 10
  40. retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  41. when: glusterfs_heketi_wipe
  42. - name: Wait for heketi pods to terminate
  43. oc_obj:
  44. namespace: "{{ glusterfs_namespace }}"
  45. kind: pod
  46. state: list
  47. selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  48. register: heketi_pod
  49. until: "heketi_pod.results.results[0]['items'] | count == 0"
  50. delay: 10
  51. retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  52. when: glusterfs_heketi_wipe
  53. - include: glusterfs_deploy.yml
  54. when: glusterfs_is_native
  55. - name: Create heketi service account
  56. oc_serviceaccount:
  57. namespace: "{{ glusterfs_namespace }}"
  58. name: "heketi-{{ glusterfs_name }}-service-account"
  59. state: present
  60. when: glusterfs_heketi_is_native
  61. - name: Add heketi service account to privileged SCC
  62. oc_adm_policy_user:
  63. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  64. resource_kind: scc
  65. resource_name: privileged
  66. state: present
  67. when: glusterfs_heketi_is_native
  68. - name: Allow heketi service account to view/edit pods
  69. oc_adm_policy_user:
  70. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  71. resource_kind: role
  72. resource_name: edit
  73. state: present
  74. when: glusterfs_heketi_is_native
  75. - name: Check for existing deploy-heketi pod
  76. oc_obj:
  77. namespace: "{{ glusterfs_namespace }}"
  78. state: list
  79. kind: pod
  80. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  81. register: heketi_pod
  82. when: glusterfs_heketi_is_native
  83. - name: Check if need to deploy deploy-heketi
  84. set_fact:
  85. glusterfs_heketi_deploy_is_missing: False
  86. when:
  87. - "glusterfs_heketi_is_native"
  88. - "heketi_pod.results.results[0]['items'] | count > 0"
  89. # deploy-heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  90. - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  91. - name: Check for existing heketi pod
  92. oc_obj:
  93. namespace: "{{ glusterfs_namespace }}"
  94. state: list
  95. kind: pod
  96. selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  97. register: heketi_pod
  98. when: glusterfs_heketi_is_native
  99. - name: Check if need to deploy heketi
  100. set_fact:
  101. glusterfs_heketi_is_missing: False
  102. when:
  103. - "glusterfs_heketi_is_native"
  104. - "heketi_pod.results.results[0]['items'] | count > 0"
  105. # heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  106. - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  107. - name: Generate topology file
  108. template:
  109. src: "{{ openshift.common.examples_content_version }}/topology.json.j2"
  110. dest: "{{ mktemp.stdout }}/topology.json"
  111. when:
  112. - glusterfs_heketi_topology_load
  113. - include: heketi_deploy_part1.yml
  114. when:
  115. - glusterfs_heketi_is_native
  116. - glusterfs_heketi_deploy_is_missing
  117. - glusterfs_heketi_is_missing
  118. - name: Set heketi URL
  119. set_fact:
  120. glusterfs_heketi_url: "localhost:8080"
  121. when:
  122. - glusterfs_heketi_is_native
  123. - name: Set heketi-cli command
  124. set_fact:
  125. glusterfs_heketi_client: "{% if glusterfs_heketi_is_native %}oc rsh {{ heketi_pod.results.results[0]['items'][0]['metadata']['name'] }} {% endif %}heketi-cli -s http://{{ glusterfs_heketi_url }} --user admin --secret '{{ glusterfs_heketi_admin_key }}'"
  126. - name: Verify heketi service
  127. command: "{{ glusterfs_heketi_client }} cluster list"
  128. changed_when: False
  129. - name: Load heketi topology
  130. command: "{{ glusterfs_heketi_client }} topology load --json={{ mktemp.stdout }}/topology.json 2>&1"
  131. register: topology_load
  132. failed_when: "topology_load.rc != 0 or 'Unable' in topology_load.stdout"
  133. when:
  134. - glusterfs_heketi_topology_load
  135. - include: heketi_deploy_part2.yml
  136. when:
  137. - glusterfs_heketi_is_native
  138. - glusterfs_heketi_is_missing
  139. - name: Create heketi user secret
  140. oc_secret:
  141. namespace: "{{ glusterfs_namespace }}"
  142. state: present
  143. name: "heketi-{{ glusterfs_name }}-user-secret"
  144. type: "kubernetes.io/glusterfs"
  145. force: True
  146. contents:
  147. - path: key
  148. data: "{{ glusterfs_heketi_user_key }}"
  149. - name: Generate GlusterFS StorageClass file
  150. template:
  151. src: "{{ openshift.common.examples_content_version }}/glusterfs-storageclass.yml.j2"
  152. dest: "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  153. - name: Create GlusterFS StorageClass
  154. oc_obj:
  155. state: present
  156. kind: storageclass
  157. name: "glusterfs-{{ glusterfs_name }}"
  158. files:
  159. - "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  160. when:
  161. - glusterfs_storageclass