main.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 | 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 | length == 0) or (central.resources[0].status.phase != "Running")
  49. #- name: is there anyone home at the api endpoint?
  50. - name: create ns, og, and sub
  51. kubernetes.core.k8s:
  52. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  53. validate_certs: no
  54. template: templates/central-ns-and-sub.yml
  55. when: not csv_is_there
  56. - name: wait until csv is there and ready
  57. k8s_info:
  58. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  59. validate_certs: no
  60. api_version: operators.coreos.com/v1alpha1
  61. kind: clusterserviceversion
  62. name: rhacs-operator.v{{ acs_z }}
  63. namespace: rhacs
  64. when: not csv_is_there
  65. register: csv
  66. until: (csv.resources | length) > 0 and csv.resources[0].status.phase == "Succeeded"
  67. retries: 30
  68. delay: 5
  69. - name: deploy cr
  70. kubernetes.core.k8s:
  71. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  72. validate_certs: no
  73. src: files/central-cr.yml
  74. when: not central_is_there
  75. - name: wait for central pod to be up
  76. k8s_info:
  77. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  78. validate_certs: no
  79. api_version: v1
  80. kind: pod
  81. namespace: rhacs
  82. label_selectors:
  83. - app = central
  84. when: not central_is_there
  85. register: central
  86. until: (central.resources | length) > 0 and central.resources[0].status.phase == "Running"
  87. retries: 30
  88. delay: 5
  89. - name: look up route
  90. k8s_info:
  91. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  92. validate_certs: no
  93. api_version: route.openshift.io/v1
  94. kind: route
  95. namespace: rhacs
  96. name: central
  97. register: central_route
  98. - assert:
  99. that: central_route.resources | length > 0
  100. fail_msg: "ERROR: Central seems to be there, but route is not present."
  101. success_msg: "OK, got route to Central."
  102. - name: store route hostname as fact
  103. set_fact:
  104. central_ep: "{{ central_route.resources[0].spec.host }}"
  105. - name: store the api endpoint in a file
  106. copy:
  107. dest: "{{ ansible_facts['user_dir'] }}/api-endpoint"
  108. content: "{{ central_ep }}:443"
  109. - name: look up secret
  110. k8s_info:
  111. kubeconfig: "{{ ansible_facts['user_dir'] }}/kubeconfig-ocp4"
  112. validate_certs: no
  113. api_version: v1
  114. kind: secret
  115. namespace: rhacs
  116. name: central-htpasswd
  117. register: central_secret
  118. - assert:
  119. that: central_secret.resources | length > 0
  120. fail_msg: "ERROR: Central seems to be there, but auth secret is not present."
  121. success_msg: "OK, got secret to Central."
  122. - name: store central pass as fact
  123. set_fact:
  124. central_pass: "{{ central_secret.resources[0].data.password }}"
  125. - name: store the password in a file
  126. copy:
  127. dest: "{{ ansible_facts['user_dir'] }}/api-password"
  128. content: "{{ central_pass | string | b64decode }}"
  129. - name: does a token exist?
  130. uri:
  131. method: GET
  132. force_basic_auth: true
  133. return_content: true
  134. validate_certs: false
  135. url: "https://{{ central_ep }}/v1/apitokens"
  136. url_username: admin
  137. url_password: "{{ central_pass | string | b64decode }}"
  138. headers:
  139. Accept: application/json
  140. Content-Type: application/json
  141. register: token_list
  142. - name: generate an api token
  143. uri:
  144. method: POST
  145. force_basic_auth: true
  146. return_content: true
  147. validate_certs: false
  148. url: "https://{{ central_ep }}/v1/apitokens/generate"
  149. url_username: admin
  150. url_password: "{{ central_pass | string | b64decode }}"
  151. body: '{"name":"automation","role":null,"roles":["Admin"]}'
  152. headers:
  153. Accept: application/json
  154. Content-Type: application/json
  155. register: api_token
  156. when: (token_list.json.tokens | items2dict(key_name='name', value_name='revoked'))["automation"] is not defined
  157. - name: store api token in a file
  158. copy:
  159. dest: "{{ ansible_facts['user_dir'] }}/api-token"
  160. content: "{{ api_token.json.token }}"
  161. when: not api_token.skipped
  162. #- name: take a policy backup (for later)
  163. ## XXX can't delete system policies XXX
  164. #
  165. ...