57 lines
2.1 KiB
YAML
57 lines
2.1 KiB
YAML
---
|
|
# Jobs relating to the ansible user.
|
|
|
|
# $RANDOM is anywhere from 0 to 32767 in BASH. This would be up to ~9 hours.
|
|
# $RANDOM / 10 can be up to about 3200 seconds, or ~55 minutes.
|
|
# $RANDOM / 20 can be up to about 1600 seconds, or ~27 minutes.
|
|
# $RANDOM / 50 can be up to about 650 seconds, or ~11 minutes.
|
|
# $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 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
|
|
ansible.builtin.cron:
|
|
user: ansible
|
|
name: "Ansible Sync"
|
|
minute: "*/30"
|
|
job: "bash -c 'sleep $(( $RANDOM / 20 )); sudo {{ ansible_pull_exec.stdout }} -v -o -U {{ git_repo_http }} --checkout {{ branch }} >>{{ ansible_cron_log }} 2>&1'"
|
|
state: present
|
|
disabled: "{{ 'yes' if no_telem else 'no' }}"
|
|
|
|
- name: General | Cron | Ansible | Create Forced Weekly Subscriber Job
|
|
ansible.builtin.cron:
|
|
user: ansible
|
|
name: "Ansible Weekly Forced Sync"
|
|
special_time: weekly
|
|
job: "bash -c 'sleep $(( $RANDOM / 1 )); sudo {{ ansible_pull_exec.stdout }} -v -U {{ git_repo_http }} --checkout {{ branch }} >>{{ ansible_cron_log }} 2>&1'"
|
|
state: present
|
|
disabled: "{{ 'yes' if no_telem else 'no' }}"
|