main.yaml 10.0 KB

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