main.yaml 7.0 KB

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