glusterfs_common.yml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 }}-admin-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. namespace: "{{ glusterfs_namespace }}"
  64. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  65. resource_kind: scc
  66. resource_name: privileged
  67. state: present
  68. when: glusterfs_heketi_is_native
  69. - name: Allow heketi service account to view/edit pods
  70. oc_adm_policy_user:
  71. namespace: "{{ glusterfs_namespace }}"
  72. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  73. resource_kind: role
  74. resource_name: edit
  75. state: present
  76. when: glusterfs_heketi_is_native
  77. - name: Check for existing deploy-heketi pod
  78. oc_obj:
  79. namespace: "{{ glusterfs_namespace }}"
  80. state: list
  81. kind: pod
  82. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  83. register: heketi_pod
  84. when: glusterfs_heketi_is_native
  85. - name: Check if need to deploy deploy-heketi
  86. set_fact:
  87. glusterfs_heketi_deploy_is_missing: False
  88. when:
  89. - "glusterfs_heketi_is_native"
  90. - "heketi_pod.results.results[0]['items'] | count > 0"
  91. # deploy-heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  92. - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  93. - name: Check for existing heketi pod
  94. oc_obj:
  95. namespace: "{{ glusterfs_namespace }}"
  96. state: list
  97. kind: pod
  98. selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  99. register: heketi_pod
  100. when: glusterfs_heketi_is_native
  101. - name: Check if need to deploy heketi
  102. set_fact:
  103. glusterfs_heketi_is_missing: False
  104. when:
  105. - "glusterfs_heketi_is_native"
  106. - "heketi_pod.results.results[0]['items'] | count > 0"
  107. # heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  108. - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  109. - name: Generate topology file
  110. template:
  111. src: "{{ openshift.common.examples_content_version }}/topology.json.j2"
  112. dest: "{{ mktemp.stdout }}/topology.json"
  113. when:
  114. - glusterfs_heketi_topology_load
  115. - name: Generate heketi admin key
  116. set_fact:
  117. glusterfs_heketi_admin_key: "{{ 32 | oo_generate_secret }}"
  118. when:
  119. - glusterfs_heketi_is_native
  120. - glusterfs_heketi_admin_key is undefined
  121. - name: Generate heketi user key
  122. set_fact:
  123. glusterfs_heketi_user_key: "{{ 32 | oo_generate_secret }}"
  124. until: "glusterfs_heketi_user_key != glusterfs_heketi_admin_key"
  125. delay: 1
  126. retries: 10
  127. when:
  128. - glusterfs_heketi_is_native
  129. - glusterfs_heketi_user_key is undefined
  130. - include: heketi_deploy_part1.yml
  131. when:
  132. - glusterfs_heketi_is_native
  133. - glusterfs_heketi_deploy_is_missing
  134. - glusterfs_heketi_is_missing
  135. - name: Set heketi-cli command
  136. set_fact:
  137. 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 }}'"
  138. - name: Verify heketi service
  139. command: "{{ glusterfs_heketi_client }} cluster list"
  140. changed_when: False
  141. - name: Load heketi topology
  142. command: "{{ glusterfs_heketi_client }} topology load --json={{ mktemp.stdout }}/topology.json 2>&1"
  143. register: topology_load
  144. failed_when: "topology_load.rc != 0 or 'Unable' in topology_load.stdout"
  145. when:
  146. - glusterfs_heketi_topology_load
  147. - include: heketi_deploy_part2.yml
  148. when:
  149. - glusterfs_heketi_is_native
  150. - glusterfs_heketi_is_missing
  151. - name: Create heketi secret
  152. oc_secret:
  153. namespace: "{{ glusterfs_namespace }}"
  154. state: present
  155. name: "heketi-{{ glusterfs_name }}-admin-secret"
  156. type: "kubernetes.io/glusterfs"
  157. force: True
  158. contents:
  159. - path: key
  160. data: "{{ glusterfs_heketi_admin_key }}"
  161. when:
  162. - glusterfs_storageclass
  163. - name: Get heketi route
  164. oc_obj:
  165. namespace: "{{ glusterfs_namespace }}"
  166. kind: route
  167. state: list
  168. name: "heketi-{{ glusterfs_name }}"
  169. register: heketi_route
  170. when:
  171. - glusterfs_storageclass
  172. - glusterfs_heketi_is_native
  173. - name: Determine StorageClass heketi URL
  174. set_fact:
  175. glusterfs_heketi_route: "{{ heketi_route.results.results[0]['spec']['host'] }}"
  176. when:
  177. - glusterfs_storageclass
  178. - glusterfs_heketi_is_native
  179. - name: Generate GlusterFS StorageClass file
  180. template:
  181. src: "{{ openshift.common.examples_content_version }}/glusterfs-storageclass.yml.j2"
  182. dest: "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  183. when:
  184. - glusterfs_storageclass
  185. - name: Create GlusterFS StorageClass
  186. oc_obj:
  187. state: present
  188. kind: storageclass
  189. name: "glusterfs-{{ glusterfs_name }}"
  190. files:
  191. - "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  192. when:
  193. - glusterfs_storageclass