Skip to content

Commit

Permalink
custom configd actions (#102)
Browse files Browse the repository at this point in the history
* issue #100 - configd actions task and handler

* issue #100 - doc configd_actions for cron task

* linted service module
  • Loading branch information
zerwes authored Sep 20, 2024
1 parent d30ac42 commit 0425990
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# some configctl infos
# https://docs.opnsense.org/manual/settingsmenu.html

# configd
- name: service configd restart # noqa no-changed-when command-instead-of-module
ansible.builtin.command: service configd restart

# alias handlers
# see: src/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php
# api endpoint /api/firewall/alias/reconfigure
Expand Down
40 changes: 40 additions & 0 deletions tasks/configd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---

# see:
# https://docs.opnsense.org/development/backend/configd.html
#
# configd_actions:
# template_name: # example myservice -> will create /usr/local/opnsense/service/conf/actions.d/actions_myservice.conf
# actionname: # something like start, stop, ...
# command:
# parameters:
# type:
# message:
# description:
#
# scripts required for the configd_actions commands can be listed in
# configd_actions_scripts
# and will be uploaded to
# /usr/local/sbin/

- name: upload custom scripts for configd actions
ansible.builtin.copy:
src: "{{ item }}"
dest: "/usr/local/sbin/{{ item }}"
mode: '0750'
owner: root
group: wheel
with_list: "{{ configd_actions_scripts | default([]) }}"

- name: install action templates
ansible.builtin.template:
src: configd_action.j2
dest: /usr/local/opnsense/service/conf/actions.d/actions_{{ _configd_action.key }}.conf
mode: '0644'
owner: root
group: wheel
with_dict: "{{ configd_actions | default({}) }}"
loop_control:
loop_var: _configd_action
label: "{{ _configd_action.key }}"
notify: service configd restart
3 changes: 3 additions & 0 deletions tasks/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
# wireguard restart : Restart WireGuard
# zfs scrub : ZFS pool scrub
# zfs trim : ZFS pool trim
#
# you can extend the commands by adding custom configd_actions
# see: tasks/configd.yml

- name: cron jobs
ansible.builtin.include_tasks: cronjobs.yml
Expand Down
9 changes: 9 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
- fetch
- always

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

- name: dnsserver
tags:
- always
Expand Down
10 changes: 10 additions & 0 deletions templates/configd_action.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#jinja2: lstrip_blocks: True
{% for action, params in _configd_action.value.items() %}
[{{ action }}]
{% for k, v in params.items() %}
{{ k }}:{{ v }}
{% endfor %}
{% if not loop.last %}

{% endif %}
{% endfor %}

0 comments on commit 0425990

Please sign in to comment.