main.yaml 6.3 KB

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