main.yaml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. ---
  2. - fail:
  3. msg: Application logs destination is required
  4. when: not openshift_logging_mux_app_host or openshift_logging_mux_app_host == ''
  5. - fail:
  6. msg: Operations logs destination is required
  7. when: not openshift_logging_mux_ops_host or openshift_logging_mux_ops_host == ''
  8. - name: Set default image variables based on deployment_type
  9. include_vars: "{{ var_file_name }}"
  10. with_first_found:
  11. - "{{ openshift_deployment_type | default(deployment_type) }}.yml"
  12. - "default_images.yml"
  13. loop_control:
  14. loop_var: var_file_name
  15. - name: Set mux image facts
  16. set_fact:
  17. openshift_logging_mux_image_prefix: "{{ openshift_logging_mux_image_prefix | default(__openshift_logging_mux_image_prefix) }}"
  18. openshift_logging_mux_image_version: "{{ openshift_logging_mux_image_version | default(__openshift_logging_mux_image_version) }}"
  19. - include_tasks: determine_version.yaml
  20. # allow passing in a tempdir
  21. - name: Create temp directory for doing work in
  22. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  23. register: mktemp
  24. changed_when: False
  25. - set_fact:
  26. tempdir: "{{ mktemp.stdout }}"
  27. - name: Create templates subdirectory
  28. file:
  29. state: directory
  30. path: "{{ tempdir }}/templates"
  31. mode: 0755
  32. changed_when: False
  33. # we want to make sure we have all the necessary components here
  34. # create service account
  35. - name: Create Mux service account
  36. oc_serviceaccount:
  37. state: present
  38. name: "aggregated-logging-mux"
  39. namespace: "{{ openshift_logging_mux_namespace }}"
  40. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  41. when: openshift_logging_image_pull_secret != ''
  42. - name: Create Mux service account
  43. oc_serviceaccount:
  44. state: present
  45. name: "aggregated-logging-mux"
  46. namespace: "{{ openshift_logging_mux_namespace }}"
  47. when:
  48. - openshift_logging_image_pull_secret == ''
  49. # set service account scc
  50. - name: Set privileged permissions for Mux
  51. oc_adm_policy_user:
  52. namespace: "{{ openshift_logging_mux_namespace }}"
  53. resource_kind: scc
  54. resource_name: privileged
  55. state: present
  56. user: "system:serviceaccount:{{ openshift_logging_mux_namespace }}:aggregated-logging-mux"
  57. # set service account permissions
  58. - name: Set cluster-reader permissions for Mux
  59. oc_adm_policy_user:
  60. namespace: "{{ openshift_logging_mux_namespace }}"
  61. resource_kind: cluster-role
  62. resource_name: cluster-reader
  63. state: present
  64. user: "system:serviceaccount:{{ openshift_logging_mux_namespace }}:aggregated-logging-mux"
  65. # set hostmount-anyuid permissions
  66. - name: Set hostmount-anyuid permissions for Mux
  67. oc_adm_policy_user:
  68. namespace: "{{ openshift_logging_mux_namespace }}"
  69. resource_kind: scc
  70. resource_name: hostmount-anyuid
  71. state: present
  72. user: "system:serviceaccount:{{ openshift_logging_mux_namespace }}:aggregated-logging-mux"
  73. # create Mux configmap
  74. - copy:
  75. src: fluent.conf
  76. dest: "{{mktemp.stdout}}/fluent-mux.conf"
  77. when: fluentd_mux_config_contents is undefined
  78. changed_when: no
  79. - copy:
  80. src: secure-forward.conf
  81. dest: "{{mktemp.stdout}}/secure-forward-mux.conf"
  82. when: fluentd_mux_securefoward_contents is undefined
  83. changed_when: no
  84. - copy:
  85. content: "{{fluentd_mux_config_contents}}"
  86. dest: "{{mktemp.stdout}}/fluent-mux.conf"
  87. when: fluentd_mux_config_contents is defined
  88. changed_when: no
  89. - copy:
  90. content: "{{fluentd_mux_secureforward_contents}}"
  91. dest: "{{mktemp.stdout}}/secure-forward-mux.conf"
  92. when: fluentd_mux_secureforward_contents is defined
  93. changed_when: no
  94. - name: Set Mux configmap
  95. oc_configmap:
  96. state: present
  97. name: "logging-mux"
  98. namespace: "{{ openshift_logging_mux_namespace }}"
  99. from_file:
  100. fluent.conf: "{{ tempdir }}/fluent-mux.conf"
  101. secure-forward.conf: "{{ tempdir }}/secure-forward-mux.conf"
  102. # create Mux secret
  103. - name: Set logging-mux secret
  104. oc_secret:
  105. state: present
  106. name: logging-mux
  107. namespace: "{{ openshift_logging_mux_namespace }}"
  108. files:
  109. - name: ca
  110. path: "{{ generated_certs_dir }}/ca.crt"
  111. - name: key
  112. path: "{{ generated_certs_dir }}/system.logging.mux.key"
  113. - name: cert
  114. path: "{{ generated_certs_dir }}/system.logging.mux.crt"
  115. - name: shared_key
  116. path: "{{ generated_certs_dir }}/mux_shared_key"
  117. # services
  118. - name: Set logging-mux service for external communication
  119. oc_service:
  120. state: present
  121. name: "logging-mux"
  122. namespace: "{{ openshift_logging_mux_namespace }}"
  123. selector:
  124. component: mux
  125. provider: openshift
  126. labels:
  127. logging-infra: 'support'
  128. ports:
  129. - name: mux-forward
  130. port: "{{ openshift_logging_mux_port }}"
  131. targetPort: "mux-forward"
  132. external_ips:
  133. - "{{ ansible_eth0.ipv4.address }}"
  134. when: openshift_logging_mux_allow_external | bool
  135. - name: Set logging-mux service for internal communication
  136. oc_service:
  137. state: present
  138. name: "logging-mux"
  139. namespace: "{{ openshift_logging_mux_namespace }}"
  140. selector:
  141. component: mux
  142. provider: openshift
  143. labels:
  144. logging-infra: 'support'
  145. ports:
  146. - name: mux-forward
  147. port: "{{ openshift_logging_mux_port }}"
  148. targetPort: "mux-forward"
  149. when: not openshift_logging_mux_allow_external | bool
  150. # create Mux DC
  151. - name: Generating mux deploymentconfig
  152. template:
  153. src: mux.j2
  154. dest: "{{mktemp.stdout}}/templates/logging-mux-dc.yaml"
  155. vars:
  156. component: mux
  157. logging_component: mux
  158. deploy_name: "logging-{{ component }}"
  159. image: "{{ openshift_logging_mux_image_prefix }}logging-fluentd:{{ openshift_logging_mux_image_version }}"
  160. es_host: "{{ openshift_logging_mux_app_host }}"
  161. es_port: "{{ openshift_logging_mux_app_port }}"
  162. ops_host: "{{ openshift_logging_mux_ops_host }}"
  163. ops_port: "{{ openshift_logging_mux_ops_port }}"
  164. mux_cpu_limit: "{{ openshift_logging_mux_cpu_limit }}"
  165. mux_cpu_request: "{{ openshift_logging_mux_cpu_request | min_cpu(openshift_logging_mux_cpu_limit | default(none)) }}"
  166. mux_memory_limit: "{{ openshift_logging_mux_memory_limit }}"
  167. mux_replicas: "{{ openshift_logging_mux_replicas | default(1) }}"
  168. mux_node_selector: "{{ openshift_logging_mux_nodeselector | default({}) }}"
  169. check_mode: no
  170. changed_when: no
  171. - name: Create Mux PVC
  172. oc_pvc:
  173. state: present
  174. name: "{{ openshift_logging_mux_file_buffer_pvc_name }}"
  175. namespace: "{{ openshift_logging_mux_namespace }}"
  176. volume_capacity: "{{ openshift_logging_mux_file_buffer_pvc_size }}"
  177. access_modes: "{{ openshift_logging_mux_file_buffer_pvc_access_modes | list }}"
  178. selector: "{{ openshift_logging_mux_file_buffer_pvc_pv_selector }}"
  179. storage_class_name: "{{ openshift_logging_mux_file_buffer_pvc_storage_class_name | default('', true) }}"
  180. when:
  181. - openshift_logging_mux_file_buffer_storage_type == "pvc"
  182. - name: Set logging-mux DC
  183. oc_obj:
  184. state: present
  185. name: logging-mux
  186. namespace: "{{ openshift_logging_mux_namespace }}"
  187. kind: dc
  188. files:
  189. - "{{ tempdir }}/templates/logging-mux-dc.yaml"
  190. delete_after: true
  191. - name: Add mux namespaces
  192. oc_project:
  193. state: present
  194. name: "{{ item }}"
  195. node_selector: ""
  196. with_items: "{{ openshift_logging_mux_namespaces | union(openshift_logging_mux_default_namespaces) }}"
  197. - name: Delete temp directory
  198. file:
  199. name: "{{ tempdir }}"
  200. state: absent
  201. changed_when: False