main.yaml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. # TODO: add aggregation secrets if necessary
  121. - name: Set logging-fluentd secret
  122. oc_secret:
  123. state: present
  124. name: logging-fluentd
  125. namespace: "{{ openshift_logging_fluentd_namespace }}"
  126. files:
  127. - name: ca
  128. path: "{{ generated_certs_dir }}/ca.crt"
  129. - name: key
  130. path: "{{ generated_certs_dir }}/system.logging.fluentd.key"
  131. - name: cert
  132. path: "{{ generated_certs_dir }}/system.logging.fluentd.crt"
  133. # create Fluentd daemonset
  134. # this should change based on the type of fluentd deployment to be done...
  135. # TODO: pass in aggregation configurations
  136. - name: Generate logging-fluentd daemonset definition
  137. template:
  138. src: "{{ __base_file_dir }}/fluentd.j2"
  139. dest: "{{ tempdir }}/templates/logging-fluentd.yaml"
  140. vars:
  141. daemonset_name: logging-fluentd
  142. daemonset_component: fluentd
  143. daemonset_container_name: fluentd-elasticsearch
  144. daemonset_serviceAccount: aggregated-logging-fluentd
  145. app_host: "{{ openshift_logging_fluentd_app_host }}"
  146. app_port: "{{ openshift_logging_fluentd_app_port }}"
  147. ops_host: "{{ openshift_logging_fluentd_ops_host }}"
  148. ops_port: "{{ openshift_logging_fluentd_ops_port }}"
  149. fluentd_nodeselector_key: "{{ openshift_logging_fluentd_nodeselector.keys() | first }}"
  150. fluentd_nodeselector_value: "{{ openshift_logging_fluentd_nodeselector.values() | first }}"
  151. fluentd_cpu_limit: "{{ openshift_logging_fluentd_cpu_limit }}"
  152. fluentd_cpu_request: "{{ openshift_logging_fluentd_cpu_request | min_cpu(openshift_logging_fluentd_cpu_limit | default(none)) }}"
  153. fluentd_memory_limit: "{{ openshift_logging_fluentd_memory_limit }}"
  154. audit_container_engine: "{{ openshift_logging_fluentd_audit_container_engine | default(False) | bool }}"
  155. audit_log_file: "{{ openshift_logging_fluentd_audit_file | default() }}"
  156. audit_pos_log_file: "{{ openshift_logging_fluentd_audit_pos_file | default() }}"
  157. check_mode: no
  158. changed_when: no
  159. - name: Set logging-fluentd daemonset
  160. oc_obj:
  161. state: present
  162. name: logging-fluentd
  163. namespace: "{{ openshift_logging_fluentd_namespace }}"
  164. kind: daemonset
  165. files:
  166. - "{{ tempdir }}/templates/logging-fluentd.yaml"
  167. delete_after: true
  168. # Scale up Fluentd
  169. - name: Retrieve list of Fluentd hosts
  170. oc_obj:
  171. state: list
  172. kind: node
  173. when: "'--all' in openshift_logging_fluentd_hosts"
  174. register: fluentd_hosts
  175. - name: Set openshift_logging_fluentd_hosts
  176. set_fact:
  177. openshift_logging_fluentd_hosts: "{{ fluentd_hosts.results.results[0]['items'] | map(attribute='metadata.name') | list }}"
  178. when: "'--all' in openshift_logging_fluentd_hosts"
  179. - include_tasks: label_and_wait.yaml
  180. vars:
  181. node: "{{ fluentd_host }}"
  182. with_items: "{{ openshift_logging_fluentd_hosts }}"
  183. loop_control:
  184. loop_var: fluentd_host
  185. - name: Delete temp directory
  186. file:
  187. name: "{{ tempdir }}"
  188. state: absent
  189. changed_when: False