glusterfs_common.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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: "secret"
  22. name: "heketi-{{ glusterfs_name }}-config-secret"
  23. - kind: "template,route,service,dc"
  24. name: "heketi-{{ glusterfs_name }}"
  25. - kind: "svc"
  26. name: "heketi-db-{{ glusterfs_name }}-endpoints"
  27. - kind: "sa"
  28. name: "heketi-{{ glusterfs_name }}-service-account"
  29. - kind: "secret"
  30. name: "heketi-{{ glusterfs_name }}-admin-secret"
  31. failed_when: False
  32. when: glusterfs_heketi_wipe
  33. - name: Wait for deploy-heketi pods to terminate
  34. oc_obj:
  35. namespace: "{{ glusterfs_namespace }}"
  36. kind: pod
  37. state: list
  38. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  39. register: heketi_pod
  40. until: "heketi_pod.results.results[0]['items'] | count == 0"
  41. delay: 10
  42. retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  43. when: glusterfs_heketi_wipe
  44. - name: Wait for heketi pods to terminate
  45. oc_obj:
  46. namespace: "{{ glusterfs_namespace }}"
  47. kind: pod
  48. state: list
  49. selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  50. register: heketi_pod
  51. until: "heketi_pod.results.results[0]['items'] | count == 0"
  52. delay: 10
  53. retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  54. when: glusterfs_heketi_wipe
  55. - include: glusterfs_deploy.yml
  56. when: glusterfs_is_native
  57. - name: Create heketi service account
  58. oc_serviceaccount:
  59. namespace: "{{ glusterfs_namespace }}"
  60. name: "heketi-{{ glusterfs_name }}-service-account"
  61. state: present
  62. when: glusterfs_heketi_is_native
  63. - name: Add heketi service account to privileged SCC
  64. oc_adm_policy_user:
  65. namespace: "{{ glusterfs_namespace }}"
  66. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  67. resource_kind: scc
  68. resource_name: privileged
  69. state: present
  70. when: glusterfs_heketi_is_native
  71. - name: Allow heketi service account to view/edit pods
  72. oc_adm_policy_user:
  73. namespace: "{{ glusterfs_namespace }}"
  74. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  75. resource_kind: role
  76. resource_name: edit
  77. state: present
  78. when: glusterfs_heketi_is_native
  79. - name: Check for existing deploy-heketi pod
  80. oc_obj:
  81. namespace: "{{ glusterfs_namespace }}"
  82. state: list
  83. kind: pod
  84. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  85. register: heketi_pod
  86. when: glusterfs_heketi_is_native
  87. - name: Check if need to deploy deploy-heketi
  88. set_fact:
  89. glusterfs_heketi_deploy_is_missing: False
  90. when:
  91. - "glusterfs_heketi_is_native"
  92. - "heketi_pod.results.results[0]['items'] | count > 0"
  93. # deploy-heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  94. - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  95. - name: Check for existing heketi pod
  96. oc_obj:
  97. namespace: "{{ glusterfs_namespace }}"
  98. state: list
  99. kind: pod
  100. selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  101. register: heketi_pod
  102. when: glusterfs_heketi_is_native
  103. - name: Check if need to deploy heketi
  104. set_fact:
  105. glusterfs_heketi_is_missing: False
  106. when:
  107. - "glusterfs_heketi_is_native"
  108. - "heketi_pod.results.results[0]['items'] | count > 0"
  109. # heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  110. - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  111. - name: Generate topology file
  112. template:
  113. src: "{{ openshift.common.examples_content_version }}/topology.json.j2"
  114. dest: "{{ mktemp.stdout }}/topology.json"
  115. when:
  116. - glusterfs_heketi_topology_load
  117. - name: Generate heketi config file
  118. template:
  119. src: "{{ openshift.common.examples_content_version }}/heketi.json.j2"
  120. dest: "{{ mktemp.stdout }}/heketi.json"
  121. when:
  122. - glusterfs_heketi_is_native
  123. - name: Generate heketi admin key
  124. set_fact:
  125. glusterfs_heketi_admin_key: "{{ 32 | oo_generate_secret }}"
  126. when:
  127. - glusterfs_heketi_is_native
  128. - glusterfs_heketi_admin_key is undefined
  129. - name: Generate heketi user key
  130. set_fact:
  131. glusterfs_heketi_user_key: "{{ 32 | oo_generate_secret }}"
  132. until: "glusterfs_heketi_user_key != glusterfs_heketi_admin_key"
  133. delay: 1
  134. retries: 10
  135. when:
  136. - glusterfs_heketi_is_native
  137. - glusterfs_heketi_user_key is undefined
  138. - name: Create heketi config secret
  139. oc_secret:
  140. namespace: "{{ glusterfs_namespace }}"
  141. state: present
  142. name: "heketi-{{ glusterfs_name }}-config-secret"
  143. force: True
  144. files:
  145. - name: heketi.json
  146. path: "{{ mktemp.stdout }}/heketi.json"
  147. - name: private_key
  148. path: "{{ glusterfs_heketi_ssh_keyfile }}"
  149. when:
  150. - glusterfs_heketi_is_native
  151. - include: heketi_deploy_part1.yml
  152. when:
  153. - glusterfs_heketi_is_native
  154. - glusterfs_heketi_deploy_is_missing
  155. - glusterfs_heketi_is_missing
  156. - name: Set heketi-cli command
  157. set_fact:
  158. glusterfs_heketi_client: "{% if glusterfs_heketi_is_native %}{{ openshift.common.client_binary }} rsh --namespace={{ glusterfs_namespace }} {{ 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 }}'"
  159. - name: Verify heketi service
  160. command: "{{ glusterfs_heketi_client }} cluster list"
  161. changed_when: False
  162. - name: Load heketi topology
  163. command: "{{ glusterfs_heketi_client }} topology load --json={{ mktemp.stdout }}/topology.json 2>&1"
  164. register: topology_load
  165. failed_when: "topology_load.rc != 0 or 'Unable' in topology_load.stdout"
  166. when:
  167. - glusterfs_heketi_topology_load
  168. - include: heketi_deploy_part2.yml
  169. when:
  170. - glusterfs_heketi_is_native
  171. - glusterfs_heketi_is_missing
  172. - name: Create heketi secret
  173. oc_secret:
  174. namespace: "{{ glusterfs_namespace }}"
  175. state: present
  176. name: "heketi-{{ glusterfs_name }}-admin-secret"
  177. type: "kubernetes.io/glusterfs"
  178. force: True
  179. contents:
  180. - path: key
  181. data: "{{ glusterfs_heketi_admin_key }}"
  182. when:
  183. - glusterfs_storageclass
  184. - name: Get heketi route
  185. oc_obj:
  186. namespace: "{{ glusterfs_namespace }}"
  187. kind: route
  188. state: list
  189. name: "heketi-{{ glusterfs_name }}"
  190. register: heketi_route
  191. when:
  192. - glusterfs_storageclass
  193. - glusterfs_heketi_is_native
  194. - name: Determine StorageClass heketi URL
  195. set_fact:
  196. glusterfs_heketi_route: "{{ heketi_route.results.results[0]['spec']['host'] }}"
  197. when:
  198. - glusterfs_storageclass
  199. - glusterfs_heketi_is_native
  200. - name: Generate GlusterFS StorageClass file
  201. template:
  202. src: "{{ openshift.common.examples_content_version }}/glusterfs-storageclass.yml.j2"
  203. dest: "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  204. when:
  205. - glusterfs_storageclass
  206. - name: Create GlusterFS StorageClass
  207. oc_obj:
  208. state: present
  209. kind: storageclass
  210. name: "glusterfs-{{ glusterfs_name }}"
  211. files:
  212. - "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  213. when:
  214. - glusterfs_storageclass