Skip to content

Commit

Permalink
implemented cron job task (#98)
Browse files Browse the repository at this point in the history
* implemented cron job task

* linted
  • Loading branch information
zerwes authored Sep 18, 2024
1 parent 490e01f commit 6d40a4e
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
11 changes: 11 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@ opn_unboundplus_uuid_sections:
domains: domain
acls: acl

opn_cron_jobs_defaults:
origin: cron
enabled: 1
minutes: 0
hours: 0
days: '*'
months: '*'
weekdays: '*'
who: root
parameters:

...
7 changes: 7 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,11 @@
when:
- config is defined
- config.changed | bool

# cron
- name: cron restart # noqa no-changed-when
ansible.builtin.command: configctl cron restart
when:
- config is defined
- config.changed | bool
...
69 changes: 69 additions & 0 deletions tasks/cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
# cron jobs
#
# opn_cron_jobs:
# 9b30c307-dd3b-470f-bf38-c894215a3016:
# origin: cron
# enabled: 1
# minutes: '*/15'
# hours: '*'
# days: '*'
# months: '*'
# weekdays: '*'
# who: root
# command: unbound dnsbl
# parameters:
# description: update unbound dnsbl
#
# see opn_cron_jobs_defaults
#
# valid commands as per 24.7.4
# command : descr
# captiveportal restart : Restart Captive Portal service
# cron restart : Restart Cron service
# ddclient force : Force ddclient update
# ddclient restart : Restart ddclient service
# dhcpd6 restart : Restart DHCPd6
# dhcpd6 start : Start DHCPd6
# dhcpd6 stop : Stop DHCPd6
# dhcpd restart : Restart DHCPd
# dhcpd start : Start DHCPd
# dhcpd stop : Stop DHCPd
# dns reload : Reload system DNS resolver configuration
# filter refresh_aliases : Update and reload firewall aliases
# firmware auto-update : Automatic firmware update
# firmware changelog cron : Firmware changelog update
# firmware poll : Firmware update check
# ids reload : Reload intrusion detection rules
# ids restart : Restart Intrusion Detection service
# ids update : Update and reload intrusion detection rules
# interface reconfigure : Periodic interface reset
# interface routes alarm : Manual gateway switch
# ipsec reload : Reload IPsec service
# ipsec restart : Restart IPsec service
# kea restart : Restart kea daemon
# monit restart : Restart Monit service
# netflow restart : Restart NetFlow service
# openssh restart : Restart OpenSSH service
# syslog archive : Rotate log files
# syslog restart : Restart System Logging service
# system ha_reconfigure_backup : HA update and reconfigure backup
# system reboot : Issue a reboot
# system remote backup : Remote backup
# unbound dnsbl : Update Unbound DNSBLs
# unbound restart : Restart Unbound DNS service
# webgui restart : Restart web GUI service
# wireguard renew : Renew DNS for WireGuard on stale connections
# wireguard restart : Restart WireGuard
# zfs scrub : ZFS pool scrub
# zfs trim : ZFS pool trim

- name: cron jobs
ansible.builtin.include_tasks: cronjobs.yml
vars:
uuid: "{{ job.key }}"
cronjobcfg: "{{ opn_cron_jobs_defaults | combine(job.value) }}"
with_dict:
- "{{ opn_cron_jobs | default({}) }}"
loop_control:
loop_var: job
11 changes: 11 additions & 0 deletions tasks/cronjobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- name: cron job {{ uuid }}
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/OPNsense/cron/jobs/job[@uuid='{{ uuid }}']/{{ item.key }}"
value: "{{ item.value }}"
pretty_print: true
notify: cron restart
with_dict: "{{ cronjobcfg }}"
8 changes: 8 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@
apply:
tags: haproxy

- name: cron
tags:
- always
ansible.builtin.include_tasks:
file: cron.yml
apply:
tags: cron

- name: trim EOF
delegate_to: localhost
ansible.builtin.lineinfile:
Expand Down

0 comments on commit 6d40a4e

Please sign in to comment.