main.yaml 9.6 KB

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