Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom configd actions #102

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %}
Loading