main.yaml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. - include_tasks: determine_version.yaml
  41. # allow passing in a tempdir
  42. - name: Create temp directory for doing work in
  43. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  44. register: mktemp
  45. changed_when: False
  46. - set_fact:
  47. tempdir: "{{ mktemp.stdout }}"
  48. - name: Create templates subdirectory
  49. file:
  50. state: directory
  51. path: "{{ tempdir }}/templates"
  52. mode: 0755
  53. changed_when: False
  54. # we want to make sure we have all the necessary components here
  55. # create service account
  56. - name: Create Fluentd service account
  57. oc_serviceaccount:
  58. state: present
  59. name: "aggregated-logging-fluentd"
  60. namespace: "{{ openshift_logging_fluentd_namespace }}"
  61. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  62. when: openshift_logging_image_pull_secret != ''
  63. - name: Create Fluentd service account
  64. oc_serviceaccount:
  65. state: present
  66. name: "aggregated-logging-fluentd"
  67. namespace: "{{ openshift_logging_fluentd_namespace }}"
  68. when:
  69. - openshift_logging_image_pull_secret == ''
  70. # set service account scc
  71. - name: Set privileged permissions for Fluentd
  72. oc_adm_policy_user:
  73. namespace: "{{ openshift_logging_fluentd_namespace }}"
  74. resource_kind: scc
  75. resource_name: privileged
  76. state: present
  77. user: "system:serviceaccount:{{ openshift_logging_fluentd_namespace }}:aggregated-logging-fluentd"
  78. # set service account permissions
  79. - name: Set cluster-reader permissions for Fluentd
  80. oc_adm_policy_user:
  81. namespace: "{{ openshift_logging_fluentd_namespace }}"
  82. resource_kind: cluster-role
  83. resource_name: cluster-reader
  84. state: present
  85. user: "system:serviceaccount:{{ openshift_logging_fluentd_namespace }}:aggregated-logging-fluentd"
  86. # create Fluentd configmap
  87. - template:
  88. src: fluent.conf.j2
  89. dest: "{{ tempdir }}/fluent.conf"
  90. vars:
  91. deploy_type: "{{ openshift_logging_fluentd_deployment_type }}"
  92. when: fluentd_config_contents is undefined
  93. changed_when: no
  94. - copy:
  95. src: fluentd-throttle-config.yaml
  96. dest: "{{ tempdir }}/fluentd-throttle-config.yaml"
  97. when: fluentd_throttle_contents is undefined
  98. changed_when: no
  99. - copy:
  100. src: secure-forward.conf
  101. dest: "{{ tempdir }}/secure-forward.conf"
  102. when: fluentd_secureforward_contents is undefined
  103. changed_when: no
  104. - copy:
  105. content: "{{ fluentd_config_contents }}"
  106. dest: "{{ tempdir }}/fluent.conf"
  107. when: fluentd_config_contents is defined
  108. changed_when: no
  109. - copy:
  110. content: "{{ fluentd_throttle_contents }}"
  111. dest: "{{ tempdir }}/fluentd-throttle-config.yaml"
  112. when: fluentd_throttle_contents is defined
  113. changed_when: no
  114. - copy:
  115. content: "{{ fluentd_secureforward_contents }}"
  116. dest: "{{ tempdir }}/secure-forward.conf"
  117. when: fluentd_secureforward_contents is defined
  118. changed_when: no
  119. - name: Set Fluentd configmap
  120. oc_configmap:
  121. state: present
  122. name: "logging-fluentd"
  123. namespace: "{{ openshift_logging_fluentd_namespace }}"
  124. from_file:
  125. fluent.conf: "{{ tempdir }}/fluent.conf"
  126. throttle-config.yaml: "{{ tempdir }}/fluentd-throttle-config.yaml"
  127. secure-forward.conf: "{{ tempdir }}/secure-forward.conf"
  128. # create Fluentd secret
  129. # TODO: add aggregation secrets if necessary
  130. - name: Set logging-fluentd secret
  131. oc_secret:
  132. state: present
  133. name: logging-fluentd
  134. namespace: "{{ openshift_logging_fluentd_namespace }}"
  135. files:
  136. - name: ca
  137. path: "{{ generated_certs_dir }}/ca.crt"
  138. - name: key
  139. path: "{{ generated_certs_dir }}/system.logging.fluentd.key"
  140. - name: cert
  141. path: "{{ generated_certs_dir }}/system.logging.fluentd.crt"
  142. # create Fluentd daemonset
  143. # this should change based on the type of fluentd deployment to be done...
  144. # TODO: pass in aggregation configurations
  145. - name: Generate logging-fluentd daemonset definition
  146. template:
  147. src: fluentd.j2
  148. dest: "{{ tempdir }}/templates/logging-fluentd.yaml"
  149. vars:
  150. daemonset_name: logging-fluentd
  151. daemonset_component: fluentd
  152. daemonset_container_name: fluentd-elasticsearch
  153. daemonset_serviceAccount: aggregated-logging-fluentd
  154. app_host: "{{ openshift_logging_fluentd_app_host }}"
  155. app_port: "{{ openshift_logging_fluentd_app_port }}"
  156. ops_host: "{{ openshift_logging_fluentd_ops_host }}"
  157. ops_port: "{{ openshift_logging_fluentd_ops_port }}"
  158. fluentd_nodeselector_key: "{{ openshift_logging_fluentd_nodeselector.keys()[0] }}"
  159. fluentd_nodeselector_value: "{{ openshift_logging_fluentd_nodeselector.values()[0] }}"
  160. fluentd_cpu_limit: "{{ openshift_logging_fluentd_cpu_limit }}"
  161. fluentd_cpu_request: "{{ openshift_logging_fluentd_cpu_request | min_cpu(openshift_logging_fluentd_cpu_limit | default(none)) }}"
  162. fluentd_memory_limit: "{{ openshift_logging_fluentd_memory_limit }}"
  163. audit_container_engine: "{{ openshift_logging_fluentd_audit_container_engine | default(False) | bool }}"
  164. audit_log_file: "{{ openshift_logging_fluentd_audit_file | default() }}"
  165. audit_pos_log_file: "{{ openshift_logging_fluentd_audit_pos_file | default() }}"
  166. check_mode: no
  167. changed_when: no
  168. - name: Set logging-fluentd daemonset
  169. oc_obj:
  170. state: present
  171. name: logging-fluentd
  172. namespace: "{{ openshift_logging_fluentd_namespace }}"
  173. kind: daemonset
  174. files:
  175. - "{{ tempdir }}/templates/logging-fluentd.yaml"
  176. delete_after: true
  177. # Scale up Fluentd
  178. - name: Retrieve list of Fluentd hosts
  179. oc_obj:
  180. state: list
  181. kind: node
  182. when: "'--all' in openshift_logging_fluentd_hosts"
  183. register: fluentd_hosts
  184. - name: Set openshift_logging_fluentd_hosts
  185. set_fact:
  186. openshift_logging_fluentd_hosts: "{{ fluentd_hosts.results.results[0]['items'] | map(attribute='metadata.name') | list }}"
  187. when: "'--all' in openshift_logging_fluentd_hosts"
  188. - include_tasks: label_and_wait.yaml
  189. vars:
  190. node: "{{ fluentd_host }}"
  191. with_items: "{{ openshift_logging_fluentd_hosts }}"
  192. loop_control:
  193. loop_var: fluentd_host
  194. - name: Delete temp directory
  195. file:
  196. name: "{{ tempdir }}"
  197. state: absent
  198. changed_when: False