From 17d360c30e1c161721b471be586c89e8220c1d0d Mon Sep 17 00:00:00 2001 From: Jeffrey van Pelt Date: Fri, 2 Oct 2020 13:24:42 +0200 Subject: [PATCH] ara_api: Add conjobs Create cron tasks to clean up old stuff from ARA, disabled by default but can be enabled if desired Change-Id: I8d54a2649bb7b82298d73b5d9b89a857807f6d1e --- roles/ara_api/defaults/main.yaml | 13 +++++++++++++ roles/ara_api/tasks/config.yaml | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/roles/ara_api/defaults/main.yaml b/roles/ara_api/defaults/main.yaml index 077387e..65bc540 100644 --- a/roles/ara_api/defaults/main.yaml +++ b/roles/ara_api/defaults/main.yaml @@ -204,3 +204,16 @@ ara_api_database_conn_max_age: 0 # timezone but Ansible doesn't provide, for example, an ansible_timezone fact # that we could use here. With that in mind, UTC is the best default for now. ara_api_time_zone: UTC + +# ARA cleanup settings +# The following settings configure daily maintenance cronjobs +ara_api_configure_cron: false + +# When configuring cronjobs, only provide the arguments for the ara CLI utility +ara_api_cleanup_crons: + - name: ara_api expire running playbooks + arguments: 'expire --server http://localhost:8000 --client http --confirm --hours 24' + special_time: 'daily' # you can also use other time arguments from the cron module + - name: ara_api prune old reports + arguments: 'playbook prune --server http://localhost:8000 --client http --confirm --days 30' + special_time: 'daily' diff --git a/roles/ara_api/tasks/config.yaml b/roles/ara_api/tasks/config.yaml index 4af53bc..597a3b7 100644 --- a/roles/ara_api/tasks/config.yaml +++ b/roles/ara_api/tasks/config.yaml @@ -110,3 +110,18 @@ notify: - restart ara-api no_log: "{{ ara_api_secure_logging }}" + +- name: Set up ARA API cronjobs + cron: + name: "{{ job['name'] }}" + special_time: "{{ job['special_time'] | default(omit) }}" + minute: "{{ job['minute'] | default(omit) }}" + hour: "{{ job['hour'] | default(omit) }}" + day: "{{ job['day'] | default(omit) }}" + weekday: "{{ job['weekday'] | default(omit) }}" + month: "{{ job['month'] | default(omit) }}" + job: "{{ ara_api_venv_path }}/bin/ara {{ job['arguments'] }} >/dev/null 2>&1" + loop: "{{ ara_api_cleanup_crons }}" + loop_control: + loop_var: 'job' + when: ara_api_configure_cron