main.yaml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. ---
  2. # fail is we don't have an endpoint for ES to connect to?
  3. - name: Ensure that Kibana has nodes to run on
  4. import_role:
  5. name: openshift_control_plane
  6. tasks_from: ensure_nodes_matching_selector.yml
  7. vars:
  8. openshift_master_ensure_nodes_selector: "{{ openshift_logging_kibana_nodeselector | map_to_pairs }}"
  9. openshift_master_ensure_nodes_service: Kibana
  10. # allow passing in a tempdir
  11. - name: Create temp directory for doing work in
  12. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  13. register: mktemp
  14. changed_when: False
  15. - set_fact:
  16. tempdir: "{{ mktemp.stdout }}"
  17. # This may not be necessary in this role
  18. - name: Create templates subdirectory
  19. file:
  20. state: directory
  21. path: "{{ tempdir }}/templates"
  22. mode: 0755
  23. changed_when: False
  24. # we want to make sure we have all the necessary components here
  25. # create service account
  26. - name: Create Kibana service account
  27. oc_serviceaccount:
  28. state: present
  29. name: "aggregated-logging-kibana"
  30. namespace: "{{ openshift_logging_namespace }}"
  31. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  32. when: openshift_logging_image_pull_secret != ''
  33. - name: Create Kibana service account
  34. oc_serviceaccount:
  35. state: present
  36. name: "aggregated-logging-kibana"
  37. namespace: "{{ openshift_logging_namespace }}"
  38. when:
  39. - openshift_logging_image_pull_secret == ''
  40. - set_fact:
  41. kibana_name: "{{ 'logging-kibana' ~ ( (openshift_logging_kibana_ops_deployment | default(false) | bool) | ternary('-ops', '')) }}"
  42. kibana_component: "{{ 'kibana' ~ ( (openshift_logging_kibana_ops_deployment | default(false) | bool) | ternary('-ops', '')) }}"
  43. # Check {{ generated_certs_dir }} for session_secret and oauth_secret
  44. - name: Checking for session_secret
  45. stat:
  46. path: "{{generated_certs_dir}}/session_secret"
  47. get_checksum: false
  48. get_attributes: false
  49. get_mime: false
  50. register: session_secret_file
  51. - name: Checking for oauth_secret
  52. stat:
  53. path: "{{generated_certs_dir}}/oauth_secret"
  54. get_checksum: false
  55. get_attributes: false
  56. get_mime: false
  57. register: oauth_secret_file
  58. # gen session_secret if necessary
  59. - name: Generate session secret
  60. copy:
  61. content: "{{ 32 | lib_utils_oo_random_word }}"
  62. dest: "{{ generated_certs_dir }}/session_secret"
  63. when:
  64. - not session_secret_file.stat.exists
  65. # gen oauth_secret if necessary
  66. - name: Generate oauth secret
  67. copy:
  68. content: "{{ 64 | lib_utils_oo_random_word }}"
  69. dest: "{{ generated_certs_dir }}/oauth_secret"
  70. when:
  71. - not oauth_secret_file.stat.exists
  72. - name: Retrieving the cert to use when generating secrets for the logging components
  73. slurp:
  74. src: "{{ generated_certs_dir }}/{{ item.file }}"
  75. register: key_pairs
  76. with_items:
  77. - { name: "ca_file", file: "ca.crt" }
  78. - { name: "kibana_internal_key", file: "kibana-internal.key"}
  79. - { name: "kibana_internal_cert", file: "kibana-internal.crt"}
  80. - { name: "server_tls", file: "server-tls.json"}
  81. - { name: "session_secret", file: "session_secret" }
  82. - { name: "oauth_secret", file: "oauth_secret" }
  83. # services
  84. - name: Set {{ kibana_name }} service
  85. oc_service:
  86. state: present
  87. name: "{{ kibana_name }}"
  88. namespace: "{{ openshift_logging_kibana_namespace }}"
  89. selector:
  90. component: "{{ kibana_component }}"
  91. provider: openshift
  92. labels:
  93. logging-infra: 'support'
  94. ports:
  95. - port: 443
  96. targetPort: "oaproxy"
  97. # create routes
  98. # TODO: set up these certs differently?
  99. - set_fact:
  100. kibana_key: "{{ lookup('file', openshift_logging_kibana_key) | b64encode }}"
  101. when: openshift_logging_kibana_key | trim | length > 0
  102. changed_when: false
  103. - set_fact:
  104. kibana_cert: "{{ lookup('file', openshift_logging_kibana_cert) | b64encode }}"
  105. when: openshift_logging_kibana_cert | trim | length > 0
  106. changed_when: false
  107. - set_fact:
  108. kibana_ca: "{{ lookup('file', openshift_logging_kibana_ca) | b64encode }}"
  109. when: openshift_logging_kibana_ca | trim | length > 0
  110. changed_when: false
  111. - set_fact:
  112. kibana_ca: "{{ key_pairs | entry_from_named_pair('ca_file') }}"
  113. when: kibana_ca is not defined
  114. changed_when: false
  115. - name: Generating Kibana route template
  116. template:
  117. src: "route_reencrypt.j2"
  118. dest: "{{ tempdir }}/templates/kibana-route.yaml"
  119. vars:
  120. obj_name: "{{ kibana_name }}"
  121. route_host: "{{ openshift_logging_kibana_hostname }}"
  122. service_name: "{{ kibana_name }}"
  123. tls_key: "{{ kibana_key | default('') | b64decode }}"
  124. tls_cert: "{{ kibana_cert | default('') | b64decode }}"
  125. tls_ca_cert: "{{ kibana_ca | b64decode }}"
  126. tls_dest_ca_cert: "{{ key_pairs | entry_from_named_pair('ca_file') | b64decode }}"
  127. edge_term_policy: "{{ openshift_logging_kibana_edge_term_policy | default('') }}"
  128. labels:
  129. component: support
  130. logging-infra: support
  131. provider: openshift
  132. changed_when: no
  133. # This currently has an issue if the host name changes
  134. - name: Setting Kibana route
  135. oc_obj:
  136. state: present
  137. name: "{{ kibana_name }}"
  138. namespace: "{{ openshift_logging_namespace }}"
  139. kind: route
  140. files:
  141. - "{{ tempdir }}/templates/kibana-route.yaml"
  142. # preserve list of current hostnames
  143. - name: Get current oauthclient hostnames
  144. oc_obj:
  145. state: list
  146. name: kibana-proxy
  147. namespace: "{{ openshift_logging_namespace }}"
  148. kind: oauthclient
  149. register: oauth_client_list
  150. - set_fact: proxy_hostnames={{ oauth_client_list.results.results[0].redirectURIs | default ([]) + ['https://' ~ openshift_logging_kibana_hostname] }}
  151. # create oauth client
  152. - name: Create oauth-client template
  153. template:
  154. src: "oauth-client.j2"
  155. dest: "{{ tempdir }}/templates/oauth-client.yml"
  156. vars:
  157. kibana_hostnames: "{{ proxy_hostnames | unique }}"
  158. secret: "{{ key_pairs | entry_from_named_pair('oauth_secret') | b64decode }}"
  159. - name: Set kibana-proxy oauth-client
  160. oc_obj:
  161. state: present
  162. name: "kibana-proxy"
  163. namespace: "{{ openshift_logging_namespace }}"
  164. kind: oauthclient
  165. files:
  166. - "{{ tempdir }}/templates/oauth-client.yml"
  167. delete_after: true
  168. # create Kibana secret
  169. - name: Set Kibana secret
  170. oc_secret:
  171. state: present
  172. name: "logging-kibana"
  173. namespace: "{{ openshift_logging_namespace }}"
  174. files:
  175. - name: ca
  176. path: "{{ generated_certs_dir }}/ca.crt"
  177. - name: key
  178. path: "{{ generated_certs_dir }}/system.logging.kibana.key"
  179. - name: cert
  180. path: "{{ generated_certs_dir }}/system.logging.kibana.crt"
  181. # create Kibana-proxy secret
  182. - name: Set Kibana Proxy secret
  183. oc_secret:
  184. state: present
  185. name: "logging-kibana-proxy"
  186. namespace: "{{ openshift_logging_namespace }}"
  187. # TODO: when possible to have both files and contents for oc_secret use this
  188. #files:
  189. #- name: server-key
  190. # path: "{{ generated_certs_dir }}/kibana-internal.key"
  191. #- name: server-cert
  192. # path: "{{ generated_certs_dir }}/kibana-internal.crt"
  193. #- name: server-tls.json
  194. # path: "{{ generated_certs_dir }}/server-tls.json"
  195. contents:
  196. - path: oauth-secret
  197. data: "{{ key_pairs | entry_from_named_pair('oauth_secret') | b64decode }}"
  198. - path: session-secret
  199. data: "{{ key_pairs | entry_from_named_pair('session_secret') | b64decode }}"
  200. - path: server-key
  201. data: "{{ key_pairs | entry_from_named_pair('kibana_internal_key') | b64decode }}"
  202. - path: server-cert
  203. data: "{{ key_pairs | entry_from_named_pair('kibana_internal_cert') | b64decode }}"
  204. - path: server-tls.json
  205. data: "{{ key_pairs | entry_from_named_pair('server_tls') | b64decode }}"
  206. # create Kibana DC
  207. - name: Generate Kibana DC template
  208. template:
  209. src: "kibana.j2"
  210. dest: "{{ tempdir }}/templates/kibana-dc.yaml"
  211. vars:
  212. component: "{{ kibana_component }}"
  213. logging_component: kibana
  214. deploy_name: "{{ kibana_name }}"
  215. es_host: "{{ openshift_logging_kibana_es_host }}"
  216. es_port: "{{ openshift_logging_kibana_es_port }}"
  217. kibana_cpu_limit: "{{ openshift_logging_kibana_cpu_limit }}"
  218. kibana_cpu_request: "{{ openshift_logging_kibana_cpu_request | min_cpu(openshift_logging_kibana_cpu_limit | default(none)) }}"
  219. kibana_memory_limit: "{{ openshift_logging_kibana_memory_limit }}"
  220. kibana_proxy_cpu_limit: "{{ openshift_logging_kibana_proxy_cpu_limit }}"
  221. kibana_proxy_cpu_request: "{{ openshift_logging_kibana_proxy_cpu_request | min_cpu(openshift_logging_kibana_proxy_cpu_limit | default(none)) }}"
  222. kibana_proxy_memory_limit: "{{ openshift_logging_kibana_proxy_memory_limit }}"
  223. kibana_replicas: "{{ openshift_logging_kibana_replicas | default (1) }}"
  224. kibana_node_selector: "{{ openshift_logging_kibana_nodeselector | default({}) }}"
  225. kibana_env_vars: "{{ openshift_logging_kibana_env_vars | default({}) }}"
  226. - name: Set Kibana DC
  227. oc_obj:
  228. state: present
  229. name: "{{ kibana_name }}"
  230. namespace: "{{ openshift_logging_namespace }}"
  231. kind: dc
  232. files:
  233. - "{{ tempdir }}/templates/kibana-dc.yaml"
  234. delete_after: true
  235. # update master configs?
  236. - name: Delete temp directory
  237. file:
  238. name: "{{ tempdir }}"
  239. state: absent
  240. changed_when: False