main.yaml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ---
  2. - name: Ensure that Logging Curator has nodes to run on
  3. import_role:
  4. name: openshift_control_plane
  5. tasks_from: ensure_nodes_matching_selector.yml
  6. vars:
  7. openshift_master_ensure_nodes_selector: "{{ openshift_logging_curator_nodeselector | map_to_pairs }}"
  8. openshift_master_ensure_nodes_service: Logging Curator
  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. # This may not be necessary in this role
  17. - name: Create templates subdirectory
  18. file:
  19. state: directory
  20. path: "{{ tempdir }}/templates"
  21. mode: 0755
  22. changed_when: False
  23. # we want to make sure we have all the necessary components here
  24. # service account
  25. - name: Create Curator service account
  26. oc_serviceaccount:
  27. state: present
  28. name: "aggregated-logging-curator"
  29. namespace: "{{ openshift_logging_namespace }}"
  30. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  31. when: openshift_logging_image_pull_secret != ''
  32. - name: Create Curator service account
  33. oc_serviceaccount:
  34. state: present
  35. name: "aggregated-logging-curator"
  36. namespace: "{{ openshift_logging_namespace }}"
  37. when:
  38. - openshift_logging_image_pull_secret == ''
  39. # secret
  40. - name: Set Curator secret
  41. oc_secret:
  42. state: present
  43. name: "logging-curator"
  44. namespace: "{{ openshift_logging_namespace }}"
  45. files:
  46. - name: ca
  47. path: "{{ generated_certs_dir }}/ca.crt"
  48. - name: key
  49. path: "{{ generated_certs_dir }}/system.logging.curator.key"
  50. - name: cert
  51. path: "{{ generated_certs_dir }}/system.logging.curator.crt"
  52. - set_fact:
  53. curator_name: "{{ 'logging-curator' ~ ( (openshift_logging_curator_ops_deployment | default(false) | bool) | ternary('-ops', '') ) }}"
  54. curator_component: "{{ 'curator' ~ ( (openshift_logging_curator_ops_deployment | default(false) | bool) | ternary('-ops', '') ) }}"
  55. - name: Detect running upgrade
  56. set_fact:
  57. is_upgrade: "{{ openshift_logging_facts['curator' ~ ( (openshift_logging_curator_ops_deployment | default(false) | bool) | ternary('_ops', '') )]['deploymentconfigs'][curator_name] is defined }}"
  58. # Cron Job - v5.x
  59. # Keep the old DC around
  60. - name: Scale the old DC to 0
  61. oc_scale:
  62. name: "{{ curator_name }}"
  63. namespace: "{{ openshift_logging_namespace }}"
  64. kind: dc
  65. replicas: 0
  66. when: is_upgrade | bool
  67. - name: Generate Curator cronjob
  68. template:
  69. src: "curator-cj.j2"
  70. dest: "{{ tempdir }}/templates/curator-cj.yaml"
  71. vars:
  72. component: "{{ curator_component }}"
  73. logging_component: curator
  74. deploy_name: "{{ curator_name }}"
  75. es_host: "{{ openshift_logging_curator_es_host }}"
  76. es_port: "{{ openshift_logging_curator_es_port }}"
  77. curator_cpu_limit: "{{ openshift_logging_curator_cpu_limit }}"
  78. curator_cpu_request: "{{ openshift_logging_curator_cpu_request | min_cpu(openshift_logging_curator_cpu_limit | default(none)) }}"
  79. curator_memory_limit: "{{ openshift_logging_curator_memory_limit }}"
  80. curator_node_selector: "{{openshift_logging_curator_nodeselector | default({})}}"
  81. cron_job_schedule: "{{ openshift_logging_curator_run_minute | default(0) }} {{ openshift_logging_curator_run_hour | default(0) }} * * *"
  82. check_mode: no
  83. changed_when: no
  84. # Copy config files
  85. - copy:
  86. src: "{{ item }}"
  87. dest: "{{ tempdir }}/{{ item }}"
  88. with_items:
  89. - "actions.yaml"
  90. - "config.yaml"
  91. - "curator.yml"
  92. # Patch existing configuration, if present
  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: "actions.yaml"
  101. new_file: "{{ tempdir }}/actions.yaml"
  102. - current_file: "curator5.yaml"
  103. new_file: "{{ tempdir }}/config.yaml"
  104. - current_file: "config.yaml"
  105. new_file: "{{ tempdir }}/curator.yml"
  106. # Create cronjob
  107. - name: Set Curator Cronjob
  108. oc_obj:
  109. state: present
  110. name: "{{ curator_name }}"
  111. namespace: "{{ openshift_logging_namespace }}"
  112. kind: cronjob
  113. files:
  114. - "{{ tempdir }}/templates/curator-cj.yaml"
  115. delete_after: true
  116. # Create config map
  117. - name: Set Curator configmap
  118. oc_configmap:
  119. state: present
  120. name: "logging-curator"
  121. namespace: "{{ openshift_logging_namespace }}"
  122. from_file:
  123. actions.yaml: "{{ tempdir }}/actions.yaml"
  124. curator5.yaml: "{{ tempdir }}/config.yaml"
  125. config.yaml: "{{ tempdir }}/curator.yml"
  126. - name: Delete temp directory
  127. file:
  128. name: "{{ tempdir }}"
  129. state: absent
  130. changed_when: False