main.yaml 7.5 KB

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