main.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. ---
  2. - name: is there already a subscription?
  3. k8s_info:
  4. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  5. validate_certs: no
  6. api_version: operators.coreos.com/v1alpha1
  7. kind: subscription
  8. namespace: rhacs
  9. name: rhacs
  10. register: sub
  11. - name: oi - is there already an operator?
  12. k8s_info:
  13. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  14. validate_certs: no
  15. api_version: operators.coreos.com/v1alpha1
  16. kind: clusterserviceversion
  17. name: "{{ sub.resources[0].status.installedCSV }}"
  18. namespace: rhacs
  19. register: csv
  20. when:
  21. - sub.resources is defined
  22. - (sub.resources | length) > 0
  23. - sub.resources[0].spec.name == "rhacs-operator"
  24. - sub.resources[0].status.installedCSV is defined
  25. - name: assert csv is there
  26. set_fact:
  27. csv_is_there: true
  28. - name: reset the above fact if not the case
  29. set_fact:
  30. csv_is_there: false
  31. when: (csv is not defined) or (csv.resources is not defined) or (csv.resources | length == 0) or (csv.resources[0].status.phase != "Succeeded")
  32. - name: is there a central pod?
  33. k8s_info:
  34. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  35. validate_certs: no
  36. api_version: v1
  37. kind: pod
  38. namespace: rhacs
  39. label_selectors:
  40. - app=central
  41. register: central
  42. - name: assert central is there
  43. set_fact:
  44. central_is_there: true
  45. - name: reset the above fact if not the case
  46. set_fact:
  47. central_is_there: false
  48. when: (central is not defined) or (central.resources is not defined) or (central.resources | length == 0) or (central.resources[0].status.phase != "Running")
  49. - name: create ns, og, and sub
  50. kubernetes.core.k8s:
  51. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  52. validate_certs: no
  53. template: templates/central-ns-and-sub.yml
  54. when: not csv_is_there
  55. - name: wait until csv is there and ready
  56. k8s_info:
  57. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  58. validate_certs: no
  59. api_version: operators.coreos.com/v1alpha1
  60. kind: clusterserviceversion
  61. name: rhacs-operator.v{{ acs_z }}
  62. namespace: rhacs
  63. when: not csv_is_there
  64. register: csv
  65. until: (csv.resources | length) > 0 and csv.resources[0].status.phase == "Succeeded"
  66. retries: 30
  67. delay: 5
  68. - name: deploy cr
  69. kubernetes.core.k8s:
  70. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  71. validate_certs: no
  72. src: files/central-cr.yml
  73. when: not central_is_there
  74. - name: wait for central pod to be up
  75. k8s_info:
  76. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  77. validate_certs: no
  78. api_version: v1
  79. kind: pod
  80. namespace: rhacs
  81. label_selectors:
  82. - app=central
  83. when: not central_is_there
  84. register: central
  85. until: (central.resources | length) > 0 and central.resources[0].status.phase == "Running"
  86. retries: 30
  87. delay: 5
  88. - name: look up route
  89. k8s_info:
  90. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  91. validate_certs: no
  92. api_version: route.openshift.io/v1
  93. kind: route
  94. namespace: rhacs
  95. name: central
  96. register: central_route
  97. - assert:
  98. that: central_route.resources | length > 0
  99. fail_msg: "ERROR: Central seems to be there, but route is not present."
  100. success_msg: "OK, got route to Central."
  101. - name: store route hostname as fact
  102. set_fact:
  103. central_ep: "{{ central_route.resources[0].spec.host }}"
  104. - name: store the api endpoint in a file
  105. copy:
  106. dest: "{{ ansible_facts['user_dir'] }}/api-endpoint"
  107. content: "{{ central_ep }}:443"
  108. - name: look up secret
  109. k8s_info:
  110. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  111. validate_certs: no
  112. api_version: v1
  113. kind: secret
  114. namespace: rhacs
  115. name: central-htpasswd
  116. register: central_secret
  117. - assert:
  118. that: central_secret.resources | length > 0
  119. fail_msg: "ERROR: Central seems to be there, but auth secret is not present."
  120. success_msg: "OK, got secret to Central."
  121. - name: store central pass as fact
  122. set_fact:
  123. central_pass: "{{ central_secret.resources[0].data.password }}"
  124. - name: store the password in a file
  125. copy:
  126. dest: "{{ ansible_facts['user_dir'] }}/api-password"
  127. content: "{{ central_pass | string | b64decode }}"
  128. - name: wait for central to be up
  129. uri:
  130. method: GET
  131. force_basic_auth: true
  132. return_content: true
  133. validate_certs: false
  134. url: "https://{{ central_ep }}/v1/centralhealth/upgradestatus"
  135. url_username: admin
  136. url_password: "{{ central_pass | string | b64decode }}"
  137. headers:
  138. Accept: application/json
  139. Content-Type: application/json
  140. register: central_status
  141. until: central_status.status == 200
  142. retries: 30
  143. delay: 5
  144. - name: does a token exist?
  145. uri:
  146. method: GET
  147. force_basic_auth: true
  148. return_content: true
  149. validate_certs: false
  150. url: "https://{{ central_ep }}/v1/apitokens?revoked=false"
  151. url_username: admin
  152. url_password: "{{ central_pass | string | b64decode }}"
  153. headers:
  154. Accept: application/json
  155. Content-Type: application/json
  156. register: token_list
  157. - name: generate an api token
  158. uri:
  159. method: POST
  160. force_basic_auth: true
  161. return_content: true
  162. validate_certs: false
  163. url: "https://{{ central_ep }}/v1/apitokens/generate"
  164. url_username: admin
  165. url_password: "{{ central_pass | string | b64decode }}"
  166. body_format: json
  167. body: '{"name":"automation","role":null,"roles":["Admin"]}'
  168. headers:
  169. Accept: application/json
  170. Content-Type: application/json
  171. register: api_token
  172. when: (token_list.json.tokens | items2dict(key_name='name', value_name='revoked'))["automation"] is not defined
  173. - name: store api token in a file
  174. copy:
  175. dest: "{{ ansible_facts['user_dir'] }}/api-token"
  176. content: "{{ api_token.json.token }}"
  177. when: (api_token.skipped is not defined) or (not api_token.skipped)
  178. #- name: take a policy backup (for later)
  179. ## XXX can't delete system policies XXX
  180. #
  181. ...