main.yaml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. ---
  2. - fail:
  3. msg: The ES_COPY feature is no longer supported. Please remove the variable from your inventory
  4. when: openshift_logging_fluentd_es_copy is defined
  5. - fail:
  6. msg: Only one Fluentd nodeselector key pair should be provided
  7. when: openshift_logging_fluentd_nodeselector.keys() | count > 1
  8. - fail:
  9. msg: Application logs destination is required
  10. when: not openshift_logging_fluentd_app_host or openshift_logging_fluentd_app_host == ''
  11. - fail:
  12. msg: Operations logs destination is required
  13. when: not openshift_logging_fluentd_ops_host or openshift_logging_fluentd_ops_host == ''
  14. - fail:
  15. msg: Invalid deployment type, one of ['hosted', 'secure-aggregator', 'secure-host'] allowed
  16. when: not openshift_logging_fluentd_deployment_type in __allowed_fluentd_types
  17. - debug:
  18. msg: openshift_logging_fluentd_use_journal is deprecated. Fluentd will automatically detect which logging driver is being used.
  19. when: openshift_logging_fluentd_use_journal is defined
  20. - debug:
  21. msg: openshift_hosted_logging_use_journal is deprecated. Fluentd will automatically detect which logging driver is being used.
  22. when: openshift_hosted_logging_use_journal is defined
  23. - fail:
  24. msg: Invalid openshift_logging_mux_client_mode [{{ openshift_logging_mux_client_mode }}], one of {{ __allowed_mux_client_modes }} allowed
  25. when: openshift_logging_mux_client_mode is defined and not openshift_logging_mux_client_mode in __allowed_mux_client_modes
  26. - debug:
  27. msg: WARNING Use of openshift_logging_mux_client_mode=minimal is not recommended due to current scaling issues
  28. when: openshift_logging_mux_client_mode is defined and openshift_logging_mux_client_mode == 'minimal'
  29. - name: Set default image variables based on openshift_deployment_type
  30. include_vars: "{{ var_file_name }}"
  31. with_first_found:
  32. - "{{ openshift_deployment_type }}.yml"
  33. - "default_images.yml"
  34. loop_control:
  35. loop_var: var_file_name
  36. - name: Set fluentd image facts
  37. set_fact:
  38. openshift_logging_fluentd_image_prefix: "{{ openshift_logging_fluentd_image_prefix | default(__openshift_logging_fluentd_image_prefix) }}"
  39. openshift_logging_fluentd_image_version: "{{ openshift_logging_fluentd_image_version | default(__openshift_logging_fluentd_image_version) }}"
  40. # allow passing in a tempdir
  41. - name: Create temp directory for doing work in
  42. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  43. register: mktemp
  44. changed_when: False
  45. - set_fact:
  46. tempdir: "{{ mktemp.stdout }}"
  47. - name: Create templates subdirectory
  48. file:
  49. state: directory
  50. path: "{{ tempdir }}/templates"
  51. mode: 0755
  52. changed_when: False
  53. # we want to make sure we have all the necessary components here
  54. # create service account
  55. - name: Create Fluentd service account
  56. oc_serviceaccount:
  57. state: present
  58. name: "aggregated-logging-fluentd"
  59. namespace: "{{ openshift_logging_fluentd_namespace }}"
  60. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  61. when: openshift_logging_image_pull_secret != ''
  62. - name: Create Fluentd service account
  63. oc_serviceaccount:
  64. state: present
  65. name: "aggregated-logging-fluentd"
  66. namespace: "{{ openshift_logging_fluentd_namespace }}"
  67. when:
  68. - openshift_logging_image_pull_secret == ''
  69. # set service account scc
  70. - name: Set privileged permissions for Fluentd
  71. oc_adm_policy_user:
  72. namespace: "{{ openshift_logging_fluentd_namespace }}"
  73. resource_kind: scc
  74. resource_name: privileged
  75. state: present
  76. user: "system:serviceaccount:{{ openshift_logging_fluentd_namespace }}:aggregated-logging-fluentd"
  77. # set service account permissions
  78. - name: Set cluster-reader permissions for Fluentd
  79. oc_adm_policy_user:
  80. namespace: "{{ openshift_logging_fluentd_namespace }}"
  81. resource_kind: cluster-role
  82. resource_name: cluster-reader
  83. state: present
  84. user: "system:serviceaccount:{{ openshift_logging_fluentd_namespace }}:aggregated-logging-fluentd"
  85. # create Fluentd configmap
  86. - template:
  87. src: "{{ __base_file_dir }}/fluent.conf.j2"
  88. dest: "{{ tempdir }}/fluent.conf"
  89. vars:
  90. deploy_type: "{{ openshift_logging_fluentd_deployment_type }}"
  91. - copy:
  92. src: "{{ __base_file_dir }}/fluentd-throttle-config.yaml"
  93. dest: "{{ tempdir }}/fluentd-throttle-config.yaml"
  94. - copy:
  95. src: "{{ __base_file_dir }}/secure-forward.conf"
  96. dest: "{{ tempdir }}/secure-forward.conf"
  97. - import_role:
  98. name: openshift_logging
  99. tasks_from: patch_configmap_files.yaml
  100. vars:
  101. configmap_name: "logging-fluentd"
  102. configmap_namespace: "{{ openshift_logging_namespace }}"
  103. configmap_file_names:
  104. - current_file: "fluent.conf"
  105. new_file: "{{ tempdir }}/fluent.conf"
  106. - current_file: "throttle-config.yaml"
  107. new_file: "{{ tempdir }}/fluentd-throttle-config.yaml"
  108. - current_file: "secure-forward.conf"
  109. new_file: "{{ tempdir }}/secure-forward.conf"
  110. - name: Set Fluentd configmap
  111. oc_configmap:
  112. state: present
  113. name: "logging-fluentd"
  114. namespace: "{{ openshift_logging_fluentd_namespace }}"
  115. from_file:
  116. fluent.conf: "{{ tempdir }}/fluent.conf"
  117. throttle-config.yaml: "{{ tempdir }}/fluentd-throttle-config.yaml"
  118. secure-forward.conf: "{{ tempdir }}/secure-forward.conf"
  119. # create Fluentd secret
  120. # if we don't provide a location for provided certs then we use from generated_certs_dir
  121. # ops will use the same certs as non-ops by default
  122. # TODO: add aggregation secrets if necessary
  123. - name: Set logging-fluentd secret
  124. oc_secret:
  125. state: present
  126. name: logging-fluentd
  127. namespace: "{{ openshift_logging_fluentd_namespace }}"
  128. files:
  129. - name: ca
  130. path: "{{ openshift_logging_fluentd_ca_path | default(generated_certs_dir ~ '/ca.crt') }}"
  131. - name: key
  132. path: "{{ openshift_logging_fluentd_key_path | default(generated_certs_dir ~ '/system.logging.fluentd.key') }}"
  133. - name: cert
  134. path: "{{ openshift_logging_fluentd_cert_path | default(generated_certs_dir ~ '/system.logging.fluentd.crt') }}"
  135. - name: ops-ca
  136. path: "{{ openshift_logging_fluentd_ops_ca_path | default(generated_certs_dir ~ '/ca.crt') }}"
  137. - name: ops-key
  138. path: "{{ openshift_logging_fluentd_ops_key_path | default(generated_certs_dir ~ '/system.logging.fluentd.key') }}"
  139. - name: ops-cert
  140. path: "{{ openshift_logging_fluentd_ops_cert_path | default(generated_certs_dir ~ '/system.logging.fluentd.crt') }}"
  141. # create Fluentd daemonset
  142. # this should change based on the type of fluentd deployment to be done...
  143. # TODO: pass in aggregation configurations
  144. - name: Generate logging-fluentd daemonset definition
  145. template:
  146. src: "{{ __base_file_dir }}/fluentd.j2"
  147. dest: "{{ tempdir }}/templates/logging-fluentd.yaml"
  148. vars:
  149. daemonset_name: logging-fluentd
  150. daemonset_component: fluentd
  151. daemonset_container_name: fluentd-elasticsearch
  152. daemonset_serviceAccount: aggregated-logging-fluentd
  153. app_host: "{{ openshift_logging_fluentd_app_host }}"
  154. app_port: "{{ openshift_logging_fluentd_app_port }}"
  155. ops_host: "{{ openshift_logging_fluentd_ops_host }}"
  156. ops_port: "{{ openshift_logging_fluentd_ops_port }}"
  157. fluentd_nodeselector_key: "{{ openshift_logging_fluentd_nodeselector.keys() | first }}"
  158. fluentd_nodeselector_value: "{{ openshift_logging_fluentd_nodeselector.values() | first }}"
  159. fluentd_cpu_limit: "{{ openshift_logging_fluentd_cpu_limit }}"
  160. fluentd_cpu_request: "{{ openshift_logging_fluentd_cpu_request | min_cpu(openshift_logging_fluentd_cpu_limit | default(none)) }}"
  161. fluentd_memory_limit: "{{ openshift_logging_fluentd_memory_limit }}"
  162. audit_container_engine: "{{ openshift_logging_fluentd_audit_container_engine | default(False) | bool }}"
  163. audit_log_file: "{{ openshift_logging_fluentd_audit_file | default() }}"
  164. audit_pos_log_file: "{{ openshift_logging_fluentd_audit_pos_file | default() }}"
  165. check_mode: no
  166. changed_when: no
  167. - name: Set logging-fluentd daemonset
  168. oc_obj:
  169. state: present
  170. name: logging-fluentd
  171. namespace: "{{ openshift_logging_fluentd_namespace }}"
  172. kind: daemonset
  173. files:
  174. - "{{ tempdir }}/templates/logging-fluentd.yaml"
  175. delete_after: true
  176. # Scale up Fluentd
  177. - name: Retrieve list of Fluentd hosts
  178. oc_obj:
  179. state: list
  180. kind: node
  181. when: "'--all' in openshift_logging_fluentd_hosts"
  182. register: fluentd_hosts
  183. - name: Set openshift_logging_fluentd_hosts
  184. set_fact:
  185. openshift_logging_fluentd_hosts: "{{ fluentd_hosts.results.results[0]['items'] | map(attribute='metadata.name') | list }}"
  186. when: "'--all' in openshift_logging_fluentd_hosts"
  187. - import_tasks: label_and_wait.yaml
  188. - name: Delete temp directory
  189. file:
  190. name: "{{ tempdir }}"
  191. state: absent
  192. changed_when: False