main.yaml 6.6 KB

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