main.yaml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. ---
  2. - name: Ensure that ElasticSearch has nodes to run on
  3. import_role:
  4. name: openshift_control_plane
  5. tasks_from: ensure_nodes_matching_selector.yml
  6. vars:
  7. openshift_master_ensure_nodes_selector: "{{ openshift_logging_es_nodeselector | map_to_pairs }}"
  8. openshift_master_ensure_nodes_service: Elasticsearch
  9. - name: Validate Elasticsearch cluster size
  10. fail: msg="The openshift_logging_es_cluster_size may only be scaled down manually. Please see official documentation on how to do this."
  11. when: openshift_logging_facts.elasticsearch.deploymentconfigs | length > openshift_logging_es_cluster_size|int
  12. - name: Validate Elasticsearch Ops cluster size
  13. fail: msg="The openshift_logging_es_ops_cluster_size may only be scaled down manually. Please see official documentation on how to do this."
  14. when: openshift_logging_facts.elasticsearch_ops.deploymentconfigs | length > openshift_logging_es_ops_cluster_size|int
  15. - fail:
  16. msg: Invalid deployment type, one of ['data-master', 'data-client', 'master', 'client'] allowed
  17. when: not openshift_logging_elasticsearch_deployment_type in __allowed_es_types
  18. - set_fact:
  19. elasticsearch_name: "{{ 'logging-elasticsearch' ~ ( (openshift_logging_elasticsearch_ops_deployment | default(false) | bool) | ternary('-ops', '')) }}"
  20. es_component: "{{ 'es' ~ ( (openshift_logging_elasticsearch_ops_deployment | default(false) | bool) | ternary('-ops', '') ) }}"
  21. - name: Set default image variables based on openshift_deployment_type
  22. include_vars: "{{ var_file_name }}"
  23. with_first_found:
  24. - "{{ openshift_deployment_type }}.yml"
  25. - "default_images.yml"
  26. loop_control:
  27. loop_var: var_file_name
  28. - name: Set elasticsearch image facts
  29. set_fact:
  30. openshift_logging_elasticsearch_proxy_image_prefix: "{{ openshift_logging_elasticsearch_proxy_image_prefix | default(__openshift_logging_elasticsearch_proxy_image_prefix) }}"
  31. openshift_logging_elasticsearch_proxy_image_version: "{{ openshift_logging_elasticsearch_proxy_image_version | default(__openshift_logging_elasticsearch_proxy_image_version) }}"
  32. openshift_logging_elasticsearch_image_prefix: "{{ openshift_logging_elasticsearch_image_prefix | default(__openshift_logging_elasticsearch_image_prefix) }}"
  33. openshift_logging_elasticsearch_image_version: "{{ openshift_logging_elasticsearch_image_version | default(__openshift_logging_elasticsearch_image_version) }}"
  34. - include_tasks: get_es_version.yml
  35. - set_fact:
  36. full_restart_cluster: True
  37. when:
  38. - _es_installed_version is defined
  39. - _es_installed_version.split('.')[0] | int < __es_version.split('.')[0] | int
  40. - set_fact:
  41. full_restart_cluster: True
  42. when:
  43. - _es_ops_installed_version is defined
  44. - _es_ops_installed_version.split('.')[0] | int < __es_version.split('.')[0] | int
  45. # allow passing in a tempdir
  46. - name: Create temp directory for doing work in
  47. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  48. register: mktemp
  49. changed_when: False
  50. - set_fact:
  51. tempdir: "{{ mktemp.stdout }}"
  52. # This may not be necessary in this role
  53. - name: Create templates subdirectory
  54. file:
  55. state: directory
  56. path: "{{ tempdir }}/templates"
  57. mode: 0755
  58. changed_when: False
  59. # we want to make sure we have all the necessary components here
  60. # service account
  61. - name: Create ES service account
  62. oc_serviceaccount:
  63. state: present
  64. name: "aggregated-logging-elasticsearch"
  65. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  66. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  67. when: openshift_logging_image_pull_secret != ''
  68. - name: Create ES service account
  69. oc_serviceaccount:
  70. state: present
  71. name: "aggregated-logging-elasticsearch"
  72. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  73. when:
  74. - openshift_logging_image_pull_secret == ''
  75. # rolebinding reader
  76. - name: Create rolebinding-reader role
  77. oc_clusterrole:
  78. state: present
  79. name: rolebinding-reader
  80. rules:
  81. - apiGroups: [""]
  82. resources: ["clusterrolebindings"]
  83. verbs: ["get"]
  84. # SA roles
  85. - name: Set rolebinding-reader permissions for ES
  86. oc_adm_policy_user:
  87. state: present
  88. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  89. resource_kind: cluster-role
  90. resource_name: rolebinding-reader
  91. user: "system:serviceaccount:{{ openshift_logging_elasticsearch_namespace }}:aggregated-logging-elasticsearch"
  92. - oc_adm_policy_user:
  93. state: present
  94. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  95. resource_kind: cluster-role
  96. resource_name: system:auth-delegator
  97. user: "system:serviceaccount:{{ openshift_logging_elasticsearch_namespace}}:aggregated-logging-elasticsearch"
  98. # logging-metrics-reader role
  99. - template:
  100. src: "{{ __base_file_dir }}/logging-metrics-role.j2"
  101. dest: "{{mktemp.stdout}}/templates/logging-metrics-role.yml"
  102. vars:
  103. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  104. - template:
  105. src: "{{ __base_file_dir }}/logging-metrics-rolebinding.j2"
  106. dest: "{{mktemp.stdout}}/templates/logging-metrics-rolebinding.yml"
  107. vars:
  108. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  109. role_namespace: "{{ openshift_logging_elasticsearch_prometheus_sa | serviceaccount_namespace(openshift_logging_elasticsearch_namespace) }}"
  110. role_user: "{{ openshift_logging_elasticsearch_prometheus_sa | serviceaccount_name }}"
  111. - name: Create logging-metrics-reader-role
  112. oc_obj:
  113. state: present
  114. name: "prometheus-metrics-viewer"
  115. kind: role
  116. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  117. files:
  118. - "{{mktemp.stdout}}/templates/logging-metrics-role.yml"
  119. delete_after: true
  120. - name: Create logging-metrics-reader-rolebinding
  121. oc_obj:
  122. state: present
  123. name: "prometheus-metrics-viewer"
  124. kind: rolebinding
  125. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  126. files:
  127. - "{{mktemp.stdout}}/templates/logging-metrics-rolebinding.yml"
  128. delete_after: true
  129. - name: Checking for passwd.yml
  130. stat: path="{{ generated_certs_dir }}/passwd.yml"
  131. register: passwd_file
  132. check_mode: no
  133. - when: passwd_file.stat.exists
  134. slurp:
  135. src: "{{ generated_certs_dir }}/passwd.yml"
  136. register: _logging_metrics_proxy_passwd
  137. - when: not passwd_file.stat.exists or openshift_logging_elasticsearch_prometheus_sa not in ( _logging_metrics_proxy_passwd['content'] | b64decode | from_yaml )
  138. template:
  139. src: passwd.j2
  140. dest: "{{ generated_certs_dir }}/passwd.yml"
  141. vars:
  142. logging_user_name: "{{ openshift_logging_elasticsearch_prometheus_sa }}"
  143. logging_user_passwd: "{{ 16 | lib_utils_oo_random_word | b64encode }}"
  144. - slurp:
  145. src: "{{ generated_certs_dir }}/passwd.yml"
  146. register: _logging_metrics_proxy_passwd
  147. # View role and binding
  148. - name: Generate logging-elasticsearch-view-role
  149. template:
  150. src: "{{ __base_file_dir }}/rolebinding.j2"
  151. dest: "{{mktemp.stdout}}/logging-elasticsearch-view-role.yaml"
  152. vars:
  153. obj_name: logging-elasticsearch-view-role
  154. roleRef:
  155. name: view
  156. subjects:
  157. - kind: ServiceAccount
  158. name: aggregated-logging-elasticsearch
  159. changed_when: no
  160. - name: Set logging-elasticsearch-view-role role
  161. oc_obj:
  162. state: present
  163. name: "logging-elasticsearch-view-role"
  164. kind: rolebinding
  165. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  166. files:
  167. - "{{ tempdir }}/logging-elasticsearch-view-role.yaml"
  168. delete_after: true
  169. # configmap
  170. - assert:
  171. that:
  172. - openshift_logging_elasticsearch_kibana_index_mode in __kibana_index_modes
  173. msg: "The openshift_logging_elasticsearch_kibana_index_mode '{{ openshift_logging_elasticsearch_kibana_index_mode }}' only supports one of: {{ __kibana_index_modes | join(', ') }}"
  174. - assert:
  175. that:
  176. - "{{ openshift_logging_es_log_appenders | length > 0 }}"
  177. msg: "The openshift_logging_es_log_appenders '{{ openshift_logging_es_log_appenders }}' has an unrecognized option and only supports the following as a list: {{ __es_log_appenders | join(', ') }}"
  178. - template:
  179. src: "{{ __base_file_dir }}/elasticsearch.yml.j2"
  180. dest: "{{ tempdir }}/elasticsearch.yml"
  181. vars:
  182. allow_cluster_reader: "{{ openshift_logging_elasticsearch_ops_allow_cluster_reader | lower | default('false') }}"
  183. es_number_of_shards: "{{ openshift_logging_es_number_of_shards | default(1) }}"
  184. es_number_of_replicas: "{{ openshift_logging_es_number_of_replicas| default(0) }}"
  185. es_kibana_index_mode: "{{ openshift_logging_elasticsearch_kibana_index_mode | default('unique') }}"
  186. changed_when: no
  187. # create diff between current configmap files and our current files
  188. - when: not openshift_logging_es5_techpreview
  189. block:
  190. - template:
  191. src: "{{ __base_file_dir }}/elasticsearch-logging.yml.j2"
  192. dest: "{{ tempdir }}/elasticsearch-logging.yml"
  193. vars:
  194. root_logger: "{{openshift_logging_es_log_appenders | join(', ')}}"
  195. changed_when: no
  196. - include_role:
  197. name: openshift_logging
  198. tasks_from: patch_configmap_files.yaml
  199. vars:
  200. configmap_name: "{{ elasticsearch_name }}"
  201. configmap_namespace: "logging"
  202. configmap_file_names:
  203. - current_file: "elasticsearch.yml"
  204. new_file: "{{ tempdir }}/elasticsearch.yml"
  205. protected_lines: ["number_of_shards", "number_of_replicas"]
  206. - current_file: "logging.yml"
  207. new_file: "{{ tempdir }}/elasticsearch-logging.yml"
  208. - slurp:
  209. src: "{{ tempdir }}/elasticsearch.yml"
  210. register: _patched_elasticsearch_config
  211. - copy:
  212. content: "{{ config_source | combine(override_config, recursive=True) | to_nice_yaml(indent=2) }}"
  213. dest: "{{ tempdir }}/elasticsearch.yml"
  214. vars:
  215. config_source: "{{ _patched_elasticsearch_config['content'] | b64decode | from_yaml }}"
  216. override_config: "{{ openshift_logging_es_config | default({}) | from_yaml }}"
  217. - name: Set ES configmap
  218. oc_configmap:
  219. state: present
  220. name: "{{ elasticsearch_name }}"
  221. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  222. from_file:
  223. elasticsearch.yml: "{{ tempdir }}/elasticsearch.yml"
  224. logging.yml: "{{ tempdir }}/elasticsearch-logging.yml"
  225. register: es_config_creation
  226. notify: "restart elasticsearch"
  227. - when: openshift_logging_es5_techpreview | bool
  228. block:
  229. - template:
  230. src: "{{ __base_file_dir }}/log4j2.properties.j2"
  231. dest: "{{ tempdir }}/log4j2.properties"
  232. vars:
  233. root_logger: "{{ openshift_logging_es_log_appenders | list }}"
  234. changed_when: no
  235. - include_role:
  236. name: openshift_logging
  237. tasks_from: patch_configmap_files.yaml
  238. vars:
  239. configmap_name: "{{ elasticsearch_name }}"
  240. configmap_namespace: "logging"
  241. configmap_file_names:
  242. - current_file: "elasticsearch.yml"
  243. new_file: "{{ tempdir }}/elasticsearch.yml"
  244. - current_file: "log4j2.properties"
  245. new_file: "{{ tempdir }}/log4j2.properties"
  246. - slurp:
  247. src: "{{ tempdir }}/elasticsearch.yml"
  248. register: _patched_elasticsearch_config
  249. - copy:
  250. content: "{{ config_source | combine(override_config, recursive=True) | to_nice_yaml(indent=2) }}"
  251. dest: "{{ tempdir }}/elasticsearch.yml"
  252. vars:
  253. config_source: "{{ _patched_elasticsearch_config['content'] | b64decode | from_yaml }}"
  254. override_config: "{{ openshift_logging_es_config | default({}) | from_yaml }}"
  255. - name: Set ES configmap
  256. oc_configmap:
  257. state: present
  258. name: "{{ elasticsearch_name }}"
  259. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  260. from_file:
  261. elasticsearch.yml: "{{ tempdir }}/elasticsearch.yml"
  262. log4j2.properties: "{{ tempdir }}/log4j2.properties"
  263. register: es_config_creation
  264. notify: "restart elasticsearch"
  265. - when: es_config_creation.changed | bool
  266. block:
  267. - set_fact:
  268. _restart_logging_components: "{{ _restart_logging_components | default([]) + [es_component] | unique }}"
  269. - shell: >
  270. {{ openshift_client_binary }} get dc -l component="{{ es_component }}" -n "{{ openshift_logging_elasticsearch_namespace }}" -o name | cut -d'/' -f2
  271. register: _es_dcs
  272. - set_fact:
  273. _restart_logging_nodes: "{{ _restart_logging_nodes | default([]) + [_es_dcs.stdout] | unique }}"
  274. when: _es_dcs.stdout != ""
  275. # secret
  276. - name: Set ES secret
  277. oc_secret:
  278. state: present
  279. name: "logging-elasticsearch"
  280. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  281. files:
  282. - name: key
  283. path: "{{ generated_certs_dir }}/logging-es.jks"
  284. - name: truststore
  285. path: "{{ generated_certs_dir }}/truststore.jks"
  286. - name: searchguard.key
  287. path: "{{ generated_certs_dir }}/elasticsearch.jks"
  288. - name: searchguard.truststore
  289. path: "{{ generated_certs_dir }}/truststore.jks"
  290. - name: admin-key
  291. path: "{{ generated_certs_dir }}/system.admin.key"
  292. - name: admin-cert
  293. path: "{{ generated_certs_dir }}/system.admin.crt"
  294. - name: admin-ca
  295. path: "{{ generated_certs_dir }}/ca.crt"
  296. - name: admin.jks
  297. path: "{{ generated_certs_dir }}/system.admin.jks"
  298. - name: passwd.yml
  299. path: "{{ generated_certs_dir }}/passwd.yml"
  300. # services
  301. - name: Set logging-{{ es_component }}-cluster service
  302. oc_service:
  303. state: present
  304. name: "logging-{{ es_component }}-cluster"
  305. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  306. selector:
  307. component: "{{ es_component }}"
  308. provider: openshift
  309. labels:
  310. logging-infra: 'support'
  311. ports:
  312. - port: 9300
  313. - name: Set logging-{{ es_component }} service
  314. oc_service:
  315. state: present
  316. name: "logging-{{ es_component }}"
  317. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  318. selector:
  319. component: "{{ es_component }}"
  320. provider: openshift
  321. labels:
  322. logging-infra: 'support'
  323. ports:
  324. - port: 9200
  325. targetPort: "restapi"
  326. - name: Set logging-{{ es_component}}-prometheus service
  327. oc_service:
  328. state: present
  329. name: "logging-{{es_component}}-prometheus"
  330. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  331. labels:
  332. logging-infra: 'support'
  333. ports:
  334. - name: proxy
  335. port: 443
  336. targetPort: 4443
  337. selector:
  338. component: "{{ es_component }}"
  339. provider: openshift
  340. - oc_edit:
  341. kind: service
  342. name: "logging-{{es_component}}-prometheus"
  343. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  344. separator: '#'
  345. content:
  346. metadata#annotations#service.alpha.openshift.io/serving-cert-secret-name: "prometheus-tls"
  347. metadata#annotations#prometheus.io/scrape: "true"
  348. metadata#annotations#prometheus.io/scheme: "https"
  349. metadata#annotations#prometheus.io/path: "_prometheus/metrics"
  350. - name: Check to see if PVC already exists
  351. oc_obj:
  352. state: list
  353. kind: pvc
  354. name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  355. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  356. register: logging_elasticsearch_pvc
  357. # logging_elasticsearch_pvc.results.results | length > 0 returns a false positive
  358. # so we check for the presence of 'stderr' to determine if the obj exists or not
  359. # the RC for existing and not existing is both 0
  360. - when:
  361. - logging_elasticsearch_pvc.results.stderr is defined
  362. - openshift_logging_elasticsearch_storage_type == "pvc"
  363. block:
  364. # storageclasses are used by default but if static then disable
  365. # storageclasses with the storageClassName set to "" in pvc.j2
  366. - name: Creating ES storage template - static
  367. template:
  368. src: "{{ __base_file_dir }}/pvc.j2"
  369. dest: "{{ tempdir }}/templates/logging-es-pvc.yml"
  370. vars:
  371. obj_name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  372. size: "{{ (openshift_logging_elasticsearch_pvc_size | trim | length == 0) | ternary('10Gi', openshift_logging_elasticsearch_pvc_size) }}"
  373. access_modes: "{{ openshift_logging_elasticsearch_pvc_access_modes | list }}"
  374. pv_selector: "{{ openshift_logging_elasticsearch_pvc_pv_selector }}"
  375. storage_class_name: "{{ openshift_logging_elasticsearch_pvc_storage_class_name | default('', true) }}"
  376. when:
  377. - not openshift_logging_elasticsearch_pvc_dynamic | bool
  378. # Storageclasses are used by default if configured
  379. - name: Creating ES storage template - dynamic
  380. template:
  381. src: "{{ __base_file_dir }}/pvc.j2"
  382. dest: "{{ tempdir }}/templates/logging-es-pvc.yml"
  383. vars:
  384. obj_name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  385. size: "{{ (openshift_logging_elasticsearch_pvc_size | trim | length == 0) | ternary('10Gi', openshift_logging_elasticsearch_pvc_size) }}"
  386. access_modes: "{{ openshift_logging_elasticsearch_pvc_access_modes | list }}"
  387. pv_selector: "{{ openshift_logging_elasticsearch_pvc_pv_selector }}"
  388. when:
  389. - openshift_logging_elasticsearch_pvc_dynamic | bool
  390. - name: Set ES storage
  391. oc_obj:
  392. state: present
  393. kind: pvc
  394. name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  395. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  396. files:
  397. - "{{ tempdir }}/templates/logging-es-pvc.yml"
  398. delete_after: true
  399. - set_fact:
  400. es_deploy_name: "logging-{{ es_component }}-{{ openshift_logging_elasticsearch_deployment_type }}-{{ 8 | lib_utils_oo_random_word('abcdefghijklmnopqrstuvwxyz0123456789') }}"
  401. when: openshift_logging_elasticsearch_deployment_name == ""
  402. - set_fact:
  403. es_deploy_name: "{{ openshift_logging_elasticsearch_deployment_name }}"
  404. when: openshift_logging_elasticsearch_deployment_name != ""
  405. # DC
  406. - name: Set ES dc templates
  407. template:
  408. src: "{{ __base_file_dir }}/es.j2"
  409. dest: "{{ tempdir }}/templates/logging-es-dc.yml"
  410. vars:
  411. es_cluster_name: "{{ es_component }}"
  412. component: "{{ es_component }}"
  413. logging_component: elasticsearch
  414. deploy_name: "{{ es_deploy_name }}"
  415. image: "{{ openshift_logging_elasticsearch_image_prefix }}logging-elasticsearch:{{ openshift_logging_elasticsearch_image_version }}"
  416. proxy_image: "{{ openshift_logging_elasticsearch_proxy_image_prefix }}oauth-proxy:{{ openshift_logging_elasticsearch_proxy_image_version }}"
  417. es_cpu_limit: "{{ openshift_logging_elasticsearch_cpu_limit | default('') }}"
  418. es_cpu_request: "{{ openshift_logging_elasticsearch_cpu_request | min_cpu(openshift_logging_elasticsearch_cpu_limit | default(none)) }}"
  419. es_memory_limit: "{{ openshift_logging_elasticsearch_memory_limit }}"
  420. es_node_selector: "{{ openshift_logging_elasticsearch_nodeselector | default({}) }}"
  421. es_storage_groups: "{{ openshift_logging_elasticsearch_storage_group | default([]) }}"
  422. es_container_security_context: "{{ _es_containers.elasticsearch.securityContext if _es_containers is defined and 'elasticsearch' in _es_containers and 'securityContext' in _es_containers.elasticsearch else None }}"
  423. deploy_type: "{{ openshift_logging_elasticsearch_deployment_type }}"
  424. es_replicas: 1
  425. basic_auth_passwd: "{{ ( _logging_metrics_proxy_passwd['content'] | b64decode | from_yaml )[openshift_logging_elasticsearch_prometheus_sa]['passwd'] | b64decode }}"
  426. es_number_of_shards: "{{ openshift_logging_es_number_of_shards | default(1) }}"
  427. es_number_of_replicas: "{{ openshift_logging_es_number_of_replicas| default(0) }}"
  428. - name: Set ES dc
  429. oc_obj:
  430. state: present
  431. name: "{{ es_deploy_name }}"
  432. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  433. kind: dc
  434. files:
  435. - "{{ tempdir }}/templates/logging-es-dc.yml"
  436. delete_after: true
  437. register: es_dc_creation
  438. notify: "restart elasticsearch"
  439. - set_fact:
  440. _restart_logging_components: "{{ _restart_logging_components | default([]) + [es_component] | unique }}"
  441. _restart_logging_nodes: "{{ _restart_logging_nodes | default([]) + [es_deploy_name] | unique }}"
  442. when: es_dc_creation.changed | bool
  443. - name: Retrieving the cert to use when generating secrets for the {{ es_component }} component
  444. slurp:
  445. src: "{{ generated_certs_dir }}/{{ item.file }}"
  446. register: key_pairs
  447. with_items:
  448. - { name: "ca_file", file: "ca.crt" }
  449. - { name: "es_key", file: "system.logging.es.key" }
  450. - { name: "es_cert", file: "system.logging.es.crt" }
  451. when: openshift_logging_es_allow_external | bool
  452. - set_fact:
  453. es_key: "{{ lookup('file', openshift_logging_es_key) | b64encode }}"
  454. when:
  455. - openshift_logging_es_key | trim | length > 0
  456. - openshift_logging_es_allow_external | bool
  457. changed_when: false
  458. - set_fact:
  459. es_cert: "{{ lookup('file', openshift_logging_es_cert) | b64encode }}"
  460. when:
  461. - openshift_logging_es_cert | trim | length > 0
  462. - openshift_logging_es_allow_external | bool
  463. changed_when: false
  464. - set_fact:
  465. es_ca: "{{ lookup('file', openshift_logging_es_ca_ext) | b64encode }}"
  466. when:
  467. - openshift_logging_es_ca_ext | trim | length > 0
  468. - openshift_logging_es_allow_external | bool
  469. changed_when: false
  470. - set_fact:
  471. es_ca: "{{ key_pairs | entry_from_named_pair('ca_file') }}"
  472. when:
  473. - es_ca is not defined
  474. - openshift_logging_es_allow_external | bool
  475. changed_when: false
  476. - name: Generating Elasticsearch {{ es_component }} route template
  477. template:
  478. src: "{{ __base_file_dir }}/route_reencrypt.j2"
  479. dest: "{{mktemp.stdout}}/templates/logging-{{ es_component }}-route.yaml"
  480. vars:
  481. obj_name: "logging-{{ es_component }}"
  482. route_host: "{{ openshift_logging_es_hostname }}"
  483. service_name: "logging-{{ es_component }}"
  484. tls_key: "{{ es_key | default('') | b64decode }}"
  485. tls_cert: "{{ es_cert | default('') | b64decode }}"
  486. tls_ca_cert: "{{ es_ca | b64decode }}"
  487. tls_dest_ca_cert: "{{ key_pairs | entry_from_named_pair('ca_file') | b64decode }}"
  488. edge_term_policy: "{{ openshift_logging_es_edge_term_policy | default('') }}"
  489. labels:
  490. component: support
  491. logging-infra: support
  492. provider: openshift
  493. changed_when: no
  494. when: openshift_logging_es_allow_external | bool
  495. # This currently has an issue if the host name changes
  496. - name: Setting Elasticsearch {{ es_component }} route
  497. oc_obj:
  498. state: present
  499. name: "logging-{{ es_component }}"
  500. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  501. kind: route
  502. files:
  503. - "{{ tempdir }}/templates/logging-{{ es_component }}-route.yaml"
  504. when: openshift_logging_es_allow_external | bool
  505. ## Placeholder for migration when necessary ##
  506. - name: Delete temp directory
  507. file:
  508. name: "{{ tempdir }}"
  509. state: absent
  510. changed_when: False