diff --git a/handlers/main.yml b/handlers/main.yml index ef75685..46683c7 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 diff --git a/tasks/configd.yml b/tasks/configd.yml new file mode 100644 index 0000000..257b6d8 --- /dev/null +++ b/tasks/configd.yml @@ -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 diff --git a/tasks/cron.yml b/tasks/cron.yml index 8d8ee95..2a91cc7 100644 --- a/tasks/cron.yml +++ b/tasks/cron.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index a728858..268f813 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,6 +15,15 @@ - fetch - always +- name: configd + tags: + - always + ansible.builtin.include_tasks: + file: configd.yml + apply: + tags: + - configd + - name: dnsserver tags: - always diff --git a/templates/configd_action.j2 b/templates/configd_action.j2 new file mode 100644 index 0000000..b18f2e2 --- /dev/null +++ b/templates/configd_action.j2 @@ -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 %}