browbeat/ansible/install/toggle-indexing-cron-job.yml
Masco 0381444f2c fix metrics start stop and cron job PATH
Change-Id: I19cbc50c40dd37f177974e70051fc43745c720a0
2024-10-15 12:41:10 +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={{ ansible_env.PATH }} && ansible-playbook {{ browbeat_path }}/ansible/install/index-ocp-data.yml > /tmp/ocp_index_cron.log 2>&1"
state: "{{ cron_state }}"