glusterfs_common.yml 5.4 KB

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