main.yaml 8.6 KB

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