main.yaml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ---
  2. - name: Set default image variables based on deployment_type
  3. include_vars: "{{ var_file_name }}"
  4. with_first_found:
  5. - "{{ openshift_deployment_type }}.yml"
  6. - "default_images.yml"
  7. loop_control:
  8. loop_var: var_file_name
  9. - name: Set curator image facts
  10. set_fact:
  11. openshift_logging_curator_image_prefix: "{{ openshift_logging_curator_image_prefix | default(__openshift_logging_curator_image_prefix) }}"
  12. openshift_logging_curator_image_version: "{{ openshift_logging_curator_image_version | default(__openshift_logging_curator_image_version) }}"
  13. - name: Detect running upgrade
  14. set_fact:
  15. is_upgrade: "{{ openshift_logging_facts['curator']['configmaps']['logging-curator'] is defined }}"
  16. - name: Ensure that Logging Curator has nodes to run on
  17. import_role:
  18. name: openshift_control_plane
  19. tasks_from: ensure_nodes_matching_selector.yml
  20. vars:
  21. openshift_master_ensure_nodes_selector: "{{ openshift_logging_curator_nodeselector | map_to_pairs }}"
  22. openshift_master_ensure_nodes_service: Logging Curator
  23. # allow passing in a tempdir
  24. - name: Create temp directory for doing work in
  25. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  26. register: mktemp
  27. changed_when: False
  28. - set_fact:
  29. tempdir: "{{ mktemp.stdout }}"
  30. # This may not be necessary in this role
  31. - name: Create templates subdirectory
  32. file:
  33. state: directory
  34. path: "{{ tempdir }}/templates"
  35. mode: 0755
  36. changed_when: False
  37. # we want to make sure we have all the necessary components here
  38. # service account
  39. - name: Create Curator service account
  40. oc_serviceaccount:
  41. state: present
  42. name: "aggregated-logging-curator"
  43. namespace: "{{ openshift_logging_namespace }}"
  44. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  45. when: openshift_logging_image_pull_secret != ''
  46. - name: Create Curator service account
  47. oc_serviceaccount:
  48. state: present
  49. name: "aggregated-logging-curator"
  50. namespace: "{{ openshift_logging_namespace }}"
  51. when:
  52. - openshift_logging_image_pull_secret == ''
  53. # secret
  54. - name: Set Curator secret
  55. oc_secret:
  56. state: present
  57. name: "logging-curator"
  58. namespace: "{{ openshift_logging_namespace }}"
  59. files:
  60. - name: ca
  61. path: "{{ generated_certs_dir }}/ca.crt"
  62. - name: key
  63. path: "{{ generated_certs_dir }}/system.logging.curator.key"
  64. - name: cert
  65. path: "{{ generated_certs_dir }}/system.logging.curator.crt"
  66. - set_fact:
  67. curator_name: "{{ 'logging-curator' ~ ( (openshift_logging_curator_ops_deployment | default(false) | bool) | ternary('-ops', '') ) }}"
  68. curator_component: "{{ 'curator' ~ ( (openshift_logging_curator_ops_deployment | default(false) | bool) | ternary('-ops', '') ) }}"
  69. # Deployment Config - v2.x
  70. - when: not openshift_logging_es5_techpreview
  71. block:
  72. - name: Generate Curator deploymentconfig
  73. template:
  74. src: "{{ __base_file_dir }}/curator.j2"
  75. dest: "{{ tempdir }}/templates/curator-dc.yaml"
  76. vars:
  77. component: "{{ curator_component }}"
  78. logging_component: curator
  79. deploy_name: "{{ curator_name }}"
  80. es_host: "{{ openshift_logging_curator_es_host }}"
  81. es_port: "{{ openshift_logging_curator_es_port }}"
  82. curator_cpu_limit: "{{ openshift_logging_curator_cpu_limit }}"
  83. curator_cpu_request: "{{ openshift_logging_curator_cpu_request | min_cpu(openshift_logging_curator_cpu_limit | default(none)) }}"
  84. curator_memory_limit: "{{ openshift_logging_curator_memory_limit }}"
  85. curator_replicas: "{{ openshift_logging_curator_replicas | default (1) }}"
  86. curator_node_selector: "{{openshift_logging_curator_nodeselector | default({})}}"
  87. check_mode: no
  88. changed_when: no
  89. - copy:
  90. src: "{{ __base_file_dir }}/curator.yml"
  91. dest: "{{ tempdir }}/curator.yml"
  92. changed_when: no
  93. - import_role:
  94. name: openshift_logging
  95. tasks_from: patch_configmap_files.yaml
  96. vars:
  97. configmap_name: "logging-curator"
  98. configmap_namespace: "{{ openshift_logging_namespace }}"
  99. configmap_file_names:
  100. - current_file: "config.yaml"
  101. new_file: "{{ tempdir }}/curator.yml"
  102. - name: Set Curator configmap
  103. oc_configmap:
  104. state: present
  105. name: "logging-curator"
  106. namespace: "{{ openshift_logging_namespace }}"
  107. from_file:
  108. config.yaml: "{{ tempdir }}/curator.yml"
  109. - name: Set Curator DC
  110. oc_obj:
  111. state: present
  112. name: "{{ curator_name }}"
  113. namespace: "{{ openshift_logging_namespace }}"
  114. kind: dc
  115. files:
  116. - "{{ tempdir }}/templates/curator-dc.yaml"
  117. delete_after: true
  118. # Cron Job - v5.x
  119. - when: openshift_logging_es5_techpreview | bool
  120. block:
  121. # Keep the old DC around
  122. - name: Scale the old DC to 0
  123. oc_scale:
  124. name: "{{ curator_name }}"
  125. namespace: "{{ openshift_logging_namespace }}"
  126. kind: dc
  127. replicas: 0
  128. when: is_upgrade | bool
  129. - name: Generate Curator cronjob
  130. template:
  131. src: "{{ __base_file_dir }}/curator-cj.j2"
  132. dest: "{{ tempdir }}/templates/curator-cj.yaml"
  133. vars:
  134. component: "{{ curator_component }}"
  135. logging_component: curator
  136. deploy_name: "{{ curator_name }}"
  137. es_host: "{{ openshift_logging_curator_es_host }}"
  138. es_port: "{{ openshift_logging_curator_es_port }}"
  139. curator_cpu_limit: "{{ openshift_logging_curator_cpu_limit }}"
  140. curator_cpu_request: "{{ openshift_logging_curator_cpu_request | min_cpu(openshift_logging_curator_cpu_limit | default(none)) }}"
  141. curator_memory_limit: "{{ openshift_logging_curator_memory_limit }}"
  142. curator_node_selector: "{{openshift_logging_curator_nodeselector | default({})}}"
  143. cron_job_schedule: "{{ openshift_logging_curator_run_minute | default(0) }} {{ openshift_logging_curator_run_hour | default(0) }} * * *"
  144. check_mode: no
  145. changed_when: no
  146. # Copy config files
  147. - copy:
  148. src: "{{ __base_file_dir }}/{{ item }}"
  149. dest: "{{ tempdir }}/{{ item }}"
  150. with_items:
  151. - "actions.yaml"
  152. - "config.yaml"
  153. - "curator.yml"
  154. # Patch existing configuration, if present
  155. - import_role:
  156. name: openshift_logging
  157. tasks_from: patch_configmap_files.yaml
  158. vars:
  159. configmap_name: "logging-curator"
  160. configmap_namespace: "{{ openshift_logging_namespace }}"
  161. configmap_file_names:
  162. - current_file: "actions.yaml"
  163. new_file: "{{ tempdir }}/actions.yaml"
  164. - current_file: "curator5.yaml"
  165. new_file: "{{ tempdir }}/config.yaml"
  166. - current_file: "config.yaml"
  167. new_file: "{{ tempdir }}/curator.yml"
  168. # Create cronjob
  169. - name: Set Curator Cronjob
  170. oc_obj:
  171. state: present
  172. name: "{{ curator_name }}"
  173. namespace: "{{ openshift_logging_namespace }}"
  174. kind: cronjob
  175. files:
  176. - "{{ tempdir }}/templates/curator-cj.yaml"
  177. delete_after: true
  178. # Create config map
  179. - name: Set Curator configmap
  180. oc_configmap:
  181. state: present
  182. name: "logging-curator"
  183. namespace: "{{ openshift_logging_namespace }}"
  184. from_file:
  185. actions.yaml: "{{ tempdir }}/actions.yaml"
  186. curator5.yaml: "{{ tempdir }}/config.yaml"
  187. config.yaml: "{{ tempdir }}/curator.yml"
  188. - name: Delete temp directory
  189. file:
  190. name: "{{ tempdir }}"
  191. state: absent
  192. changed_when: False