browbeat/ansible/install/toggle-indexing-cron-job.yml
Masco 77c5a5ed92 make configurable the kubeburner indexing period
Change-Id: I56aaf32fecb11ae260a89817fc7e77bf69b7991d
2024-09-24 17:58:26 +05:30

36 lines
1.3 KiB
YAML

---
- hosts: localhost
vars:
cron_state: "present"
tasks:
- block:
- name: Enure the log file exist
stat:
path: "/tmp/ocp_index_cron.log"
register: log_file
- name: find the age of file(last modification)
set_fact:
file_age: "{{ ((ansible_date_time.epoch | int) - (log_file.stat.mtime | int)) / 60 }}"
when: log_file.stat.exists
- name: run the ansible task with the start time
include_role:
name: index-ocp-data
vars:
start_time: "{{ log_file.stat.mtime | int }}"
when: log_file.stat.exists and (file_age | int < kubeburner_index_interval | int)
- name: run the ansible task without start time
include_role:
name: index-ocp-data
when: not log_file.stat.exists or (file_age | int >= kubeburner_index_interval | int)
when: cron_state == "absent"
- name: toggle the indexing OCP data cron job
cron:
name: "Index ocp data for the given time"
minute: "*/{{ kubeburner_index_interval | int }}"
job: "PATH=/usr/local/bin:/usr/bin:/bin && /usr/bin/ansible-playbook {{ browbeat_path }}/ansible/install/index-ocp-data.yml > /tmp/ocp_index_cron.log 2>&1"
state: "{{ cron_state }}"