main.yaml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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: path="{{generated_certs_dir}}/session_secret"
  46. register: session_secret_file
  47. - name: Checking for oauth_secret
  48. stat: path="{{generated_certs_dir}}/oauth_secret"
  49. register: oauth_secret_file
  50. # gen session_secret if necessary
  51. - name: Generate session secret
  52. copy:
  53. content: "{{ 200 | lib_utils_oo_random_word }}"
  54. dest: "{{ generated_certs_dir }}/session_secret"
  55. when:
  56. - not session_secret_file.stat.exists
  57. # gen oauth_secret if necessary
  58. - name: Generate oauth secret
  59. copy:
  60. content: "{{ 64 | lib_utils_oo_random_word }}"
  61. dest: "{{ generated_certs_dir }}/oauth_secret"
  62. when:
  63. - not oauth_secret_file.stat.exists
  64. - name: Retrieving the cert to use when generating secrets for the logging components
  65. slurp:
  66. src: "{{ generated_certs_dir }}/{{ item.file }}"
  67. register: key_pairs
  68. with_items:
  69. - { name: "ca_file", file: "ca.crt" }
  70. - { name: "kibana_internal_key", file: "kibana-internal.key"}
  71. - { name: "kibana_internal_cert", file: "kibana-internal.crt"}
  72. - { name: "server_tls", file: "server-tls.json"}
  73. - { name: "session_secret", file: "session_secret" }
  74. - { name: "oauth_secret", file: "oauth_secret" }
  75. # services
  76. - name: Set {{ kibana_name }} service
  77. oc_service:
  78. state: present
  79. name: "{{ kibana_name }}"
  80. namespace: "{{ openshift_logging_kibana_namespace }}"
  81. selector:
  82. component: "{{ kibana_component }}"
  83. provider: openshift
  84. labels:
  85. logging-infra: 'support'
  86. ports:
  87. - port: 443
  88. targetPort: "oaproxy"
  89. # create routes
  90. # TODO: set up these certs differently?
  91. - set_fact:
  92. kibana_key: "{{ lookup('file', openshift_logging_kibana_key) | b64encode }}"
  93. when: openshift_logging_kibana_key | trim | length > 0
  94. changed_when: false
  95. - set_fact:
  96. kibana_cert: "{{ lookup('file', openshift_logging_kibana_cert) | b64encode }}"
  97. when: openshift_logging_kibana_cert | trim | length > 0
  98. changed_when: false
  99. - set_fact:
  100. kibana_ca: "{{ lookup('file', openshift_logging_kibana_ca) | b64encode }}"
  101. when: openshift_logging_kibana_ca | trim | length > 0
  102. changed_when: false
  103. - set_fact:
  104. kibana_ca: "{{ key_pairs | entry_from_named_pair('ca_file') }}"
  105. when: kibana_ca is not defined
  106. changed_when: false
  107. - name: Generating Kibana route template
  108. template:
  109. src: "{{ __base_file_dir }}/route_reencrypt.j2"
  110. dest: "{{ tempdir }}/templates/kibana-route.yaml"
  111. vars:
  112. obj_name: "{{ kibana_name }}"
  113. route_host: "{{ openshift_logging_kibana_hostname }}"
  114. service_name: "{{ kibana_name }}"
  115. tls_key: "{{ kibana_key | default('') | b64decode }}"
  116. tls_cert: "{{ kibana_cert | default('') | b64decode }}"
  117. tls_ca_cert: "{{ kibana_ca | b64decode }}"
  118. tls_dest_ca_cert: "{{ key_pairs | entry_from_named_pair('ca_file') | b64decode }}"
  119. edge_term_policy: "{{ openshift_logging_kibana_edge_term_policy | default('') }}"
  120. labels:
  121. component: support
  122. logging-infra: support
  123. provider: openshift
  124. changed_when: no
  125. # This currently has an issue if the host name changes
  126. - name: Setting Kibana route
  127. oc_obj:
  128. state: present
  129. name: "{{ kibana_name }}"
  130. namespace: "{{ openshift_logging_namespace }}"
  131. kind: route
  132. files:
  133. - "{{ tempdir }}/templates/kibana-route.yaml"
  134. # preserve list of current hostnames
  135. - name: Get current oauthclient hostnames
  136. oc_obj:
  137. state: list
  138. name: kibana-proxy
  139. namespace: "{{ openshift_logging_namespace }}"
  140. kind: oauthclient
  141. register: oauth_client_list
  142. - set_fact: proxy_hostnames={{ oauth_client_list.results.results[0].redirectURIs | default ([]) + ['https://' ~ openshift_logging_kibana_hostname] }}
  143. # create oauth client
  144. - name: Create oauth-client template
  145. template:
  146. src: "{{ __base_file_dir }}/oauth-client.j2"
  147. dest: "{{ tempdir }}/templates/oauth-client.yml"
  148. vars:
  149. kibana_hostnames: "{{ proxy_hostnames | unique }}"
  150. secret: "{{ key_pairs | entry_from_named_pair('oauth_secret') | b64decode }}"
  151. - name: Set kibana-proxy oauth-client
  152. oc_obj:
  153. state: present
  154. name: "kibana-proxy"
  155. namespace: "{{ openshift_logging_namespace }}"
  156. kind: oauthclient
  157. files:
  158. - "{{ tempdir }}/templates/oauth-client.yml"
  159. delete_after: true
  160. # create Kibana secret
  161. - name: Set Kibana secret
  162. oc_secret:
  163. state: present
  164. name: "logging-kibana"
  165. namespace: "{{ openshift_logging_namespace }}"
  166. files:
  167. - name: ca
  168. path: "{{ generated_certs_dir }}/ca.crt"
  169. - name: key
  170. path: "{{ generated_certs_dir }}/system.logging.kibana.key"
  171. - name: cert
  172. path: "{{ generated_certs_dir }}/system.logging.kibana.crt"
  173. # create Kibana-proxy secret
  174. - name: Set Kibana Proxy secret
  175. oc_secret:
  176. state: present
  177. name: "logging-kibana-proxy"
  178. namespace: "{{ openshift_logging_namespace }}"
  179. # TODO: when possible to have both files and contents for oc_secret use this
  180. #files:
  181. #- name: server-key
  182. # path: "{{ generated_certs_dir }}/kibana-internal.key"
  183. #- name: server-cert
  184. # path: "{{ generated_certs_dir }}/kibana-internal.crt"
  185. #- name: server-tls.json
  186. # path: "{{ generated_certs_dir }}/server-tls.json"
  187. contents:
  188. - path: oauth-secret
  189. data: "{{ key_pairs | entry_from_named_pair('oauth_secret') | b64decode }}"
  190. - path: session-secret
  191. data: "{{ key_pairs | entry_from_named_pair('session_secret') | b64decode }}"
  192. - path: server-key
  193. data: "{{ key_pairs | entry_from_named_pair('kibana_internal_key') | b64decode }}"
  194. - path: server-cert
  195. data: "{{ key_pairs | entry_from_named_pair('kibana_internal_cert') | b64decode }}"
  196. - path: server-tls.json
  197. data: "{{ key_pairs | entry_from_named_pair('server_tls') | b64decode }}"
  198. # create Kibana DC
  199. - name: Generate Kibana DC template
  200. template:
  201. src: "{{ __base_file_dir }}/kibana.j2"
  202. dest: "{{ tempdir }}/templates/kibana-dc.yaml"
  203. vars:
  204. component: "{{ kibana_component }}"
  205. logging_component: kibana
  206. deploy_name: "{{ kibana_name }}"
  207. es_host: "{{ openshift_logging_kibana_es_host }}"
  208. es_port: "{{ openshift_logging_kibana_es_port }}"
  209. kibana_cpu_limit: "{{ openshift_logging_kibana_cpu_limit }}"
  210. kibana_cpu_request: "{{ openshift_logging_kibana_cpu_request | min_cpu(openshift_logging_kibana_cpu_limit | default(none)) }}"
  211. kibana_memory_limit: "{{ openshift_logging_kibana_memory_limit }}"
  212. kibana_proxy_cpu_limit: "{{ openshift_logging_kibana_proxy_cpu_limit }}"
  213. kibana_proxy_cpu_request: "{{ openshift_logging_kibana_proxy_cpu_request | min_cpu(openshift_logging_kibana_proxy_cpu_limit | default(none)) }}"
  214. kibana_proxy_memory_limit: "{{ openshift_logging_kibana_proxy_memory_limit }}"
  215. kibana_replicas: "{{ openshift_logging_kibana_replicas | default (1) }}"
  216. kibana_node_selector: "{{ openshift_logging_kibana_nodeselector | default({}) }}"
  217. kibana_env_vars: "{{ openshift_logging_kibana_env_vars | default({}) }}"
  218. - name: Set Kibana DC
  219. oc_obj:
  220. state: present
  221. name: "{{ kibana_name }}"
  222. namespace: "{{ openshift_logging_namespace }}"
  223. kind: dc
  224. files:
  225. - "{{ tempdir }}/templates/kibana-dc.yaml"
  226. delete_after: true
  227. # update master configs?
  228. - name: Delete temp directory
  229. file:
  230. name: "{{ tempdir }}"
  231. state: absent
  232. changed_when: False