main.yaml 6.8 KB

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