From d4b3c57cc914d70c04a8e2d5abc7997088299e8d Mon Sep 17 00:00:00 2001 From: Hyperling Date: Fri, 2 Oct 2026 10:49:53 -0700 Subject: [PATCH] ansible, add rotating of the log file. --- tasks/general/cron/ansible.yml | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tasks/general/cron/ansible.yml b/tasks/general/cron/ansible.yml index 9995f98..6d84dc8 100644 --- a/tasks/general/cron/ansible.yml +++ b/tasks/general/cron/ansible.yml @@ -8,13 +8,37 @@ # $RANDOM / 100 can be up to about 320 seconds, or ~5 minutes. # This prevents multiple systems from hitting it at the exact same time. -- name: General | Cron | Ansible | Facts - set_fact: +- name: General | Cron | Ansible | Facts 01 + ansible.builtin.set_fact: #ansible_cron_log: "~/{{ ansible_hostname }}.ansible-pull.`date +'%Y%m%d-%H%M%S'`.log" ansible_cron_log: "~/{{ ansible_hostname }}.ansible-pull.log" +- name: General | Cron | Ansible | Facts 02 + ansible.builtin.set_fact: + ansible_cron_log_old: "{{ ansible_cron_log }}.old" + + +- name: General | Cron | Ansible | Log | Delete Old + ansible.builtin.file: + path: "{{ ansible_cron_log_old }}" + state: absent + +- name: General | Cron | Ansible | Log | Check + ansible.builtin.stat: + path: "{{ ansible_cron_log }}" + register: ansible_cron_log_check + +- name: General | Cron | Ansible | Log | Rename [if >1MB] + ansible.builtin.copy: + src: "{{ ansible_cron_log }}" + dest: "{{ ansible_cron_log_old }}" + mode: "0755" + when: ansible_cron_log_check.stat.exists + and ansible_cron_log_check.stat.size > 1000000 + + - name: General | Cron | Ansible | Create Subscriber Job - cron: + ansible.builtin.cron: user: ansible name: "Ansible Sync" minute: "*/30" @@ -23,7 +47,7 @@ disabled: "{{ 'yes' if no_telem else 'no' }}" - name: General | Cron | Ansible | Create Forced Weekly Subscriber Job - cron: + ansible.builtin.cron: user: ansible name: "Ansible Weekly Forced Sync" special_time: weekly