main.yaml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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:
  36. kibana_name: "{{ 'logging-kibana' ~ ( (openshift_logging_kibana_ops_deployment | default(false) | bool) | ternary('-ops', '')) }}"
  37. kibana_component: "{{ 'kibana' ~ ( (openshift_logging_kibana_ops_deployment | default(false) | bool) | ternary('-ops', '')) }}"
  38. - name: Retrieving the cert to use when generating secrets for the logging components
  39. slurp:
  40. src: "{{ generated_certs_dir }}/{{ item.file }}"
  41. register: key_pairs
  42. with_items:
  43. - { name: "ca_file", file: "ca.crt" }
  44. - { name: "kibana_internal_key", file: "kibana-internal.key"}
  45. - { name: "kibana_internal_cert", file: "kibana-internal.crt"}
  46. - { name: "server_tls", file: "server-tls.json"}
  47. # services
  48. - name: Set {{ kibana_name }} service
  49. oc_service:
  50. state: present
  51. name: "{{ kibana_name }}"
  52. namespace: "{{ openshift_logging_kibana_namespace }}"
  53. selector:
  54. component: "{{ kibana_component }}"
  55. provider: openshift
  56. # labels:
  57. # - logging-infra: 'support'
  58. ports:
  59. - port: 443
  60. targetPort: "oaproxy"
  61. # create routes
  62. # TODO: set up these certs differently?
  63. - set_fact:
  64. kibana_key: "{{ lookup('file', openshift_logging_kibana_key) | b64encode }}"
  65. when: "{{ openshift_logging_kibana_key | trim | length > 0 }}"
  66. changed_when: false
  67. - set_fact:
  68. kibana_cert: "{{ lookup('file', openshift_logging_kibana_cert) | b64encode }}"
  69. when: "{{ openshift_logging_kibana_cert | trim | length > 0 }}"
  70. changed_when: false
  71. - set_fact:
  72. kibana_ca: "{{ lookup('file', openshift_logging_kibana_ca) | b64encode }}"
  73. when: "{{ openshift_logging_kibana_ca | trim | length > 0 }}"
  74. changed_when: false
  75. - set_fact:
  76. kibana_ca: "{{ key_pairs | entry_from_named_pair('ca_file') }}"
  77. when: kibana_ca is not defined
  78. changed_when: false
  79. - name: Generating Kibana route template
  80. template:
  81. src: route_reencrypt.j2
  82. dest: "{{ tempdir }}/templates/kibana-route.yaml"
  83. vars:
  84. obj_name: "{{ kibana_name }}"
  85. route_host: "{{ openshift_logging_kibana_hostname }}"
  86. service_name: "{{ kibana_name }}"
  87. tls_key: "{{ kibana_key | default('') | b64decode }}"
  88. tls_cert: "{{ kibana_cert | default('') | b64decode }}"
  89. tls_ca_cert: "{{ kibana_ca | b64decode }}"
  90. tls_dest_ca_cert: "{{ key_pairs | entry_from_named_pair('ca_file') | b64decode }}"
  91. edge_term_policy: "{{ openshift_logging_kibana_edge_term_policy | default('') }}"
  92. labels:
  93. component: support
  94. logging-infra: support
  95. provider: openshift
  96. changed_when: no
  97. # This currently has an issue if the host name changes
  98. - name: Setting Kibana route
  99. oc_obj:
  100. state: present
  101. name: "{{ kibana_name }}"
  102. namespace: "{{ openshift_logging_namespace }}"
  103. kind: route
  104. files:
  105. - "{{ tempdir }}/templates/kibana-route.yaml"
  106. # gen session_secret -- if necessary
  107. # TODO: make idempotent
  108. - name: Generate proxy session
  109. set_fact:
  110. session_secret: "{{ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | random_word(200) }}"
  111. check_mode: no
  112. # gen oauth_secret -- if necessary
  113. # TODO: make idempotent
  114. - name: Generate oauth client secret
  115. set_fact:
  116. oauth_secret: "{{ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | random_word(64) }}"
  117. check_mode: no
  118. # create oauth client
  119. - name: Create oauth-client template
  120. template:
  121. src: oauth-client.j2
  122. dest: "{{ tempdir }}/templates/oauth-client.yml"
  123. vars:
  124. kibana_hostname: "{{ openshift_logging_kibana_hostname }}"
  125. secret: "{{ oauth_secret }}"
  126. - name: Set kibana-proxy oauth-client
  127. oc_obj:
  128. state: present
  129. name: "kibana-proxy"
  130. namespace: "{{ openshift_logging_namespace }}"
  131. kind: oauthclient
  132. files:
  133. - "{{ tempdir }}/templates/oauth-client.yml"
  134. delete_after: true
  135. # create Kibana secret
  136. - name: Set Kibana secret
  137. oc_secret:
  138. state: present
  139. name: "logging-kibana"
  140. namespace: "{{ openshift_logging_namespace }}"
  141. files:
  142. - name: ca
  143. path: "{{ generated_certs_dir }}/ca.crt"
  144. - name: key
  145. path: "{{ generated_certs_dir }}/system.logging.kibana.key"
  146. - name: cert
  147. path: "{{ generated_certs_dir }}/system.logging.kibana.crt"
  148. # create Kibana-proxy secret
  149. - name: Set Kibana Proxy secret
  150. oc_secret:
  151. state: present
  152. name: "logging-kibana-proxy"
  153. namespace: "{{ openshift_logging_namespace }}"
  154. # files:
  155. # - name: server-key
  156. # path: "{{ generated_certs_dir }}/kibana-internal.key"
  157. # - name: server-cert
  158. # path: "{{ generated_certs_dir }}/kibana-internal.crt"
  159. # - name: server-tls
  160. # path: "{{ generated_certs_dir }}/server-tls.json"
  161. contents:
  162. - path: oauth-secret
  163. data: "{{ oauth_secret }}"
  164. - path: session-secret
  165. data: "{{ session_secret }}"
  166. - path: server-key
  167. data: "{{ key_pairs | entry_from_named_pair('kibana_internal_key') | b64decode }}"
  168. - path: server-cert
  169. data: "{{ key_pairs | entry_from_named_pair('kibana_internal_cert') | b64decode }}"
  170. - path: server-tls
  171. data: "{{ key_pairs | entry_from_named_pair('server_tls') | b64decode }}"
  172. # create Kibana DC
  173. - name: Generate Kibana DC template
  174. template:
  175. src: kibana.j2
  176. dest: "{{ tempdir }}/templates/kibana-dc.yaml"
  177. vars:
  178. component: "{{ kibana_component }}"
  179. logging_component: kibana
  180. deploy_name: "{{ kibana_name }}"
  181. image: "{{ openshift_logging_image_prefix }}logging-kibana:{{ openshift_logging_image_version }}"
  182. proxy_image: "{{ openshift_logging_image_prefix }}logging-auth-proxy:{{ openshift_logging_image_version }}"
  183. es_host: "{{ openshift_logging_kibana_es_host }}"
  184. es_port: "{{ openshift_logging_kibana_es_port }}"
  185. kibana_cpu_limit: "{{ openshift_logging_kibana_cpu_limit }}"
  186. kibana_memory_limit: "{{ openshift_logging_kibana_memory_limit }}"
  187. kibana_proxy_cpu_limit: "{{ openshift_logging_kibana_proxy_cpu_limit }}"
  188. kibana_proxy_memory_limit: "{{ openshift_logging_kibana_proxy_memory_limit }}"
  189. replicas: "{{ openshift_logging_kibana_replicas | default (0) }}"
  190. kibana_node_selector: "{{ openshift_logging_kibana_nodeselector | default({}) }}"
  191. - name: Set Kibana DC
  192. oc_obj:
  193. state: present
  194. name: "{{ kibana_name }}"
  195. namespace: "{{ openshift_logging_namespace }}"
  196. kind: dc
  197. files:
  198. - "{{ tempdir }}/templates/kibana-dc.yaml"
  199. delete_after: true
  200. # Scale up Kibana -- is this really necessary?
  201. - name: Start Kibana
  202. oc_scale:
  203. kind: dc
  204. name: "{{ kibana_name }}"
  205. namespace: "{{ openshift_logging_namespace }}"
  206. replicas: "{{ openshift_logging_kibana_replicas | default (1) }}"
  207. # update master configs?
  208. - name: Delete temp directory
  209. file:
  210. name: "{{ tempdir }}"
  211. state: absent
  212. changed_when: False