glusterfs_common.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. ---
  2. - name: Make sure heketi-client is installed
  3. package: name=heketi-client state=present
  4. when:
  5. - not openshift.common.is_atomic | bool
  6. - not glusterfs_heketi_is_native | bool
  7. - name: Verify heketi-cli is installed
  8. shell: "command -v {{ glusterfs_heketi_cli }} >/dev/null 2>&1 || { echo >&2 'ERROR: Make sure heketi-cli is available, then re-run the installer'; exit 1; }"
  9. changed_when: False
  10. when:
  11. - not glusterfs_heketi_is_native | bool
  12. - name: Verify target namespace exists
  13. oc_project:
  14. state: present
  15. name: "{{ glusterfs_namespace }}"
  16. node_selector: "{% if glusterfs_use_default_selector %}{{ omit }}{% endif %}"
  17. when: glusterfs_is_native or glusterfs_heketi_is_native or glusterfs_storageclass
  18. - name: Delete pre-existing heketi resources
  19. oc_obj:
  20. namespace: "{{ glusterfs_namespace }}"
  21. kind: "{{ item.kind }}"
  22. name: "{{ item.name | default(omit) }}"
  23. selector: "{{ item.selector | default(omit) }}"
  24. state: absent
  25. with_items:
  26. - kind: "template,route,service,dc,jobs,secret"
  27. selector: "deploy-heketi"
  28. - kind: "svc"
  29. name: "heketi-storage-endpoints"
  30. - kind: "secret"
  31. name: "heketi-{{ glusterfs_name | default }}-topology-secret"
  32. - kind: "secret"
  33. name: "heketi-{{ glusterfs_name | default }}-config-secret"
  34. - kind: "template,route,service,dc"
  35. name: "heketi-{{ glusterfs_name | default }}"
  36. - kind: "svc"
  37. name: "heketi-db-{{ glusterfs_name | default }}-endpoints"
  38. - kind: "sa"
  39. name: "heketi-{{ glusterfs_name | default }}-service-account"
  40. - kind: "secret"
  41. name: "heketi-{{ glusterfs_name | default }}-admin-secret"
  42. failed_when: False
  43. when: glusterfs_heketi_wipe
  44. - name: Wait for deploy-heketi pods to terminate
  45. oc_obj:
  46. namespace: "{{ glusterfs_namespace }}"
  47. kind: pod
  48. state: list
  49. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  50. register: deploy_heketi_pod
  51. until: "deploy_heketi_pod.results.results[0]['items'] | count == 0"
  52. delay: 10
  53. retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  54. when: glusterfs_heketi_wipe
  55. - name: Wait for heketi pods to terminate
  56. oc_obj:
  57. namespace: "{{ glusterfs_namespace }}"
  58. kind: pod
  59. state: list
  60. selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  61. register: heketi_pod
  62. until: "heketi_pod.results.results[0]['items'] | count == 0"
  63. delay: 10
  64. retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  65. when: glusterfs_heketi_wipe
  66. - include: glusterfs_deploy.yml
  67. when: glusterfs_is_native
  68. - name: Create heketi service account
  69. oc_serviceaccount:
  70. namespace: "{{ glusterfs_namespace }}"
  71. name: "heketi-{{ glusterfs_name }}-service-account"
  72. state: present
  73. when: glusterfs_heketi_is_native
  74. - name: Add heketi service account to privileged SCC
  75. oc_adm_policy_user:
  76. namespace: "{{ glusterfs_namespace }}"
  77. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  78. resource_kind: scc
  79. resource_name: privileged
  80. state: present
  81. when: glusterfs_heketi_is_native
  82. - name: Allow heketi service account to view/edit pods
  83. oc_adm_policy_user:
  84. namespace: "{{ glusterfs_namespace }}"
  85. user: "system:serviceaccount:{{ glusterfs_namespace }}:heketi-{{ glusterfs_name }}-service-account"
  86. resource_kind: role
  87. resource_name: edit
  88. state: present
  89. when: glusterfs_heketi_is_native
  90. - name: Check for existing deploy-heketi pod
  91. oc_obj:
  92. namespace: "{{ glusterfs_namespace }}"
  93. state: list
  94. kind: pod
  95. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  96. register: deploy_heketi_pod
  97. when: glusterfs_heketi_is_native
  98. - name: Check if need to deploy deploy-heketi
  99. set_fact:
  100. glusterfs_heketi_deploy_is_missing: False
  101. when:
  102. - "glusterfs_heketi_is_native"
  103. - "deploy_heketi_pod.results.results[0]['items'] | count > 0"
  104. # deploy-heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  105. - "deploy_heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  106. - name: Check for existing heketi pod
  107. oc_obj:
  108. namespace: "{{ glusterfs_namespace }}"
  109. state: list
  110. kind: pod
  111. selector: "glusterfs=heketi-{{ glusterfs_name }}-pod"
  112. register: heketi_pod
  113. when: glusterfs_heketi_is_native
  114. - name: Check if need to deploy heketi
  115. set_fact:
  116. glusterfs_heketi_is_missing: False
  117. when:
  118. - "glusterfs_heketi_is_native"
  119. - "heketi_pod.results.results[0]['items'] | count > 0"
  120. # heketi is not missing when there are one or more pods with matching labels whose 'Ready' status is True
  121. - "heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count > 0"
  122. - name: Generate topology file
  123. template:
  124. src: "{{ openshift.common.examples_content_version }}/topology.json.j2"
  125. dest: "{{ mktemp.stdout }}/topology.json"
  126. when:
  127. - glusterfs_heketi_topology_load
  128. - name: Generate heketi config file
  129. template:
  130. src: "{{ openshift.common.examples_content_version }}/heketi.json.j2"
  131. dest: "{{ mktemp.stdout }}/heketi.json"
  132. when:
  133. - glusterfs_heketi_is_native
  134. - name: Get heketi admin secret
  135. oc_secret:
  136. state: list
  137. namespace: "{{ glusterfs_namespace }}"
  138. name: "heketi-{{ glusterfs_name }}-admin-secret"
  139. decode: True
  140. register: glusterfs_heketi_admin_secret
  141. - name: Set heketi admin key
  142. set_fact:
  143. glusterfs_heketi_admin_key: "{{ glusterfs_heketi_admin_secret.results.decoded.key }}"
  144. when:
  145. - glusterfs_is_native
  146. - glusterfs_heketi_admin_secret.results.results[0]
  147. - name: Generate heketi admin key
  148. set_fact:
  149. glusterfs_heketi_admin_key: "{{ 32 | oo_generate_secret }}"
  150. when:
  151. - glusterfs_heketi_is_native
  152. - glusterfs_heketi_admin_key is undefined
  153. - name: Generate heketi user key
  154. set_fact:
  155. glusterfs_heketi_user_key: "{{ 32 | oo_generate_secret }}"
  156. until: "glusterfs_heketi_user_key != glusterfs_heketi_admin_key"
  157. delay: 1
  158. retries: 10
  159. when:
  160. - glusterfs_heketi_is_native
  161. - glusterfs_heketi_user_key is undefined
  162. - name: Copy heketi private key
  163. copy:
  164. src: "{{ glusterfs_heketi_ssh_keyfile | default(omit) }}"
  165. content: "{{ '' if glusterfs_heketi_ssh_keyfile is undefined else omit }}"
  166. dest: "{{ mktemp.stdout }}/private_key"
  167. - name: Create heketi config secret
  168. oc_secret:
  169. namespace: "{{ glusterfs_namespace }}"
  170. state: present
  171. name: "heketi-{{ glusterfs_name }}-config-secret"
  172. force: True
  173. files:
  174. - name: heketi.json
  175. path: "{{ mktemp.stdout }}/heketi.json"
  176. - name: private_key
  177. path: "{{ mktemp.stdout }}/private_key"
  178. when:
  179. - glusterfs_heketi_is_native
  180. - include: heketi_deploy_part1.yml
  181. when:
  182. - glusterfs_heketi_is_native
  183. - glusterfs_heketi_deploy_is_missing
  184. - glusterfs_heketi_is_missing
  185. - name: Wait for deploy-heketi pod
  186. oc_obj:
  187. namespace: "{{ glusterfs_namespace }}"
  188. kind: pod
  189. state: list
  190. selector: "glusterfs=deploy-heketi-{{ glusterfs_name }}-pod"
  191. register: deploy_heketi_pod
  192. until:
  193. - "deploy_heketi_pod.results.results[0]['items'] | count > 0"
  194. # Pod's 'Ready' status must be True
  195. - "deploy_heketi_pod.results.results[0]['items'] | oo_collect(attribute='status.conditions') | oo_collect(attribute='status', filters={'type': 'Ready'}) | map('bool') | select | list | count == 1"
  196. delay: 10
  197. retries: "{{ (glusterfs_timeout | int / 10) | int }}"
  198. when:
  199. - glusterfs_heketi_is_native
  200. - not glusterfs_heketi_deploy_is_missing
  201. - glusterfs_heketi_is_missing
  202. - name: Set heketi-cli command
  203. set_fact:
  204. glusterfs_heketi_client: "{% if glusterfs_heketi_is_native %}{{ openshift.common.client_binary }} rsh --namespace={{ glusterfs_namespace }} {%if not glusterfs_heketi_is_missing %}{{ heketi_pod.results.results[0]['items'][0]['metadata']['name'] }}{% else %}{{ deploy_heketi_pod.results.results[0]['items'][0]['metadata']['name'] }}{% endif %} {% endif %}{{ glusterfs_heketi_cli }} -s http://{% if glusterfs_heketi_is_native %}localhost:8080{% else %}{{ glusterfs_heketi_url }}:{{ glusterfs_heketi_port }}{% endif %} --user admin {% if glusterfs_heketi_admin_key is defined %}--secret '{{ glusterfs_heketi_admin_key }}'{% endif %}"
  205. - name: Verify heketi service
  206. command: "{{ glusterfs_heketi_client }} cluster list"
  207. changed_when: False
  208. - name: Place heketi topology on heketi Pod
  209. shell: "{{ openshift.common.client_binary }} exec --namespace={{ glusterfs_namespace }} -i {%if not glusterfs_heketi_is_missing %}{{ heketi_pod.results.results[0]['items'][0]['metadata']['name'] }}{% else %}{{ deploy_heketi_pod.results.results[0]['items'][0]['metadata']['name'] }}{% endif %} -- bash -c 'mkdir -p {{ mktemp.stdout }} && cat > {{ mktemp.stdout }}/topology.json' < {{ mktemp.stdout }}/topology.json"
  210. when:
  211. - glusterfs_heketi_is_native
  212. - name: Load heketi topology
  213. command: "{{ glusterfs_heketi_client }} topology load --json={{ mktemp.stdout }}/topology.json 2>&1"
  214. register: topology_load
  215. failed_when: "topology_load.rc != 0 or 'Unable' in topology_load.stdout"
  216. when:
  217. - glusterfs_heketi_topology_load
  218. - include: heketi_deploy_part2.yml
  219. when:
  220. - glusterfs_heketi_is_native
  221. - glusterfs_heketi_is_missing
  222. - name: Create heketi secret
  223. oc_secret:
  224. namespace: "{{ glusterfs_namespace }}"
  225. state: present
  226. name: "heketi-{{ glusterfs_name }}-admin-secret"
  227. type: "kubernetes.io/glusterfs"
  228. force: True
  229. contents:
  230. - path: key
  231. data: "{{ glusterfs_heketi_admin_key }}"
  232. when:
  233. - glusterfs_storageclass
  234. - glusterfs_heketi_admin_key is defined
  235. - name: Get heketi route
  236. oc_obj:
  237. namespace: "{{ glusterfs_namespace }}"
  238. kind: route
  239. state: list
  240. name: "heketi-{{ glusterfs_name }}"
  241. register: heketi_route
  242. when:
  243. - glusterfs_storageclass
  244. - glusterfs_heketi_is_native
  245. - name: Determine StorageClass heketi URL
  246. set_fact:
  247. glusterfs_heketi_route: "{{ heketi_route.results.results[0]['spec']['host'] }}"
  248. when:
  249. - glusterfs_storageclass
  250. - glusterfs_heketi_is_native
  251. - name: Generate GlusterFS StorageClass file
  252. template:
  253. src: "{{ openshift.common.examples_content_version }}/glusterfs-storageclass.yml.j2"
  254. dest: "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  255. when:
  256. - glusterfs_storageclass
  257. - name: Create GlusterFS StorageClass
  258. oc_obj:
  259. state: present
  260. kind: storageclass
  261. name: "glusterfs-{{ glusterfs_name }}"
  262. files:
  263. - "{{ mktemp.stdout }}/glusterfs-storageclass.yml"
  264. when:
  265. - glusterfs_storageclass