I am checking to see if a cron job exists and if it doesn't, add it. Because we use random times (for both hours and minutes) I cannot search for the entire line. Here is what I have:
- name: UPDATE_WAZUH
lineinfile:
path: /var/spool/cron/crontabs/root
regexp: "find /var/log/nginx/nginx_error.log"
state: present
register: remove_nginx_logs
- name: UPDATE_WAZUH
cron:
name: "empty nginx logs"
minute: "{{ 59|random }}"
hour: "{{ 23|random }}"
job: 'find /var/log/nginx/nginx_error.log -name "*.gz" -type f -mtime +15 -delete'
when: remove_wazuh_logs is defined
One of the errors I get is:
line is required with state=present
When I try adding line to lineinfile like this:
- name: UPDATE_WAZUH
lineinfile:
path: /var/spool/cron/crontabs/root
regexp: "find /var/log/nginx/nginx_error.log"
state: present
line:
'find /var/log/nginx/nginx_error.log -name "*.gz" -type f -mtime +15 -delete'
register: remove_nginx_logs
It still fails. How can I accomplish this?