main.yaml 7.1 KB

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