glusterfs_common.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. - name: Generate heketi admin key
  114. set_fact:
  115. glusterfs_heketi_admin_key: "{{ 32 | oo_generate_secret }}"
  116. when:
  117. - glusterfs_heketi_is_native
  118. - glusterfs_heketi_admin_key is undefined
  119. - name: Generate heketi user key
  120. set_fact:
  121. glusterfs_heketi_user_key: "{{ 32 | oo_generate_secret }}"
  122. until: "glusterfs_heketi_user_key != glusterfs_heketi_admin_key"
  123. delay: 1
  124. retries: 10
  125. when:
  126. - glusterfs_heketi_is_native
  127. - glusterfs_heketi_user_key is undefined
  128. - include: heketi_deploy_part1.yml
  129. when:
  130. - glusterfs_heketi_is_native
  131. - glusterfs_heketi_deploy_is_missing
  132. - glusterfs_heketi_is_missing
  133. - name: Set heketi-cli command
  134. set_fact:
  135. glusterfs_heketi_client: "{% if glusterfs_heketi_is_native %}oc rsh {{ heketi_pod.results.results[0]['items'][0]['metadata']['name'] }} {% endif %}heketi-cli -s http://{% if glusterfs_heketi_is_native %}localhost:8080{% else %}{{ glusterfs_heketi_url }}:{{ glusterfs_heketi_port }}{% endif %} --user admin --secret '{{ glusterfs_heketi_admin_key }}'"
  136. - name: Verify heketi service
  137. command: "{{ glusterfs_heketi_client }} cluster list"
  138. changed_when: False
  139. - name: Load heketi topology
  140. command: "{{ glusterfs_heketi_client }} topology load --json={{ mktemp.stdout }}/topology.json 2>&1"
  141. register: topology_load
  142. failed_when: "topology_load.rc != 0 or 'Unable' in topology_load.stdout"
  143. when:
  144. - glusterfs_heketi_topology_load
  145. - include: heketi_deploy_part2.yml
  146. when:
  147. - glusterfs_heketi_is_native
  148. - glusterfs_heketi_is_missing
  149. - name: Create heketi secret
  150. oc_secret:
  151. namespace: "{{ glusterfs_namespace }}"
  152. state: present
  153. name: "heketi-{{ glusterfs_name }}-secret"
  154. type: "kubernetes.io/glusterfs"
  155. force: True
  156. contents:
  157. - path: key
  158. data: "{{ glusterfs_heketi_admin_key }}"
  159. when:
  160. - glusterfs_storageclass
  161. - name: Get heketi route
  162. oc_obj:
  163. namespace: "{{ glusterfs_namespace }}"
  164. kind: route
  165. state: list
  166. name: "heketi-{{ glusterfs_name }}"
  167. register: heketi_route
  168. when:
  169. - glusterfs_storageclass
  170. - glusterfs_heketi_is_native
  171. - name: Determine StorageClass heketi URL
  172. set_fact:
  173. glusterfs_heketi_route: "{{ heketi_route.results.results[0]['spec']['host'] }}"
  174. when:
  175. - glusterfs_storageclass
  176. - glusterfs_heketi_is_native
  177. - name: Generate GlusterFS StorageClass file
  178. template:
  179. src: "{{ openshift.common.examples_content_version }}/glusterfs-storageclass.yml.j2"
  180. dest: "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  181. when:
  182. - glusterfs_storageclass
  183. - name: Create GlusterFS StorageClass
  184. oc_obj:
  185. state: present
  186. kind: storageclass
  187. name: "glusterfs-{{ glusterfs_name }}"
  188. files:
  189. - "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  190. when:
  191. - glusterfs_storageclass