From 4b6c7219aa7de8f9808c80a7798c8f07cabf670f Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Thu, 17 Sep 2026 11:57:38 +0200 Subject: [PATCH] feat: Manage ipforwarding --- defaults/main.yml | 3 +++ handlers/main.yml | 9 +++++++++ tasks/configuration.yml | 11 +++++++++++ templates/100-ip_forwarding.conf.j2 | 4 ++++ 4 files changed, 27 insertions(+) create mode 100644 templates/100-ip_forwarding.conf.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 0a884ba..f22ee27 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,5 +7,8 @@ nftables_conf_template: nftables.conf.j2 # Default configuration path nftables_conf_path: /etc/nftables.conf +# Path of sysctl ipforwarding file +nftables_ip_forwarding_path: "" + # List of rules to deploy nftables_rules: [] diff --git a/handlers/main.yml b/handlers/main.yml index 1747910..69ee26d 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -8,3 +8,12 @@ enabled: true masked: false become: true + +- name: Enable 100-ip_forwarding.conf + ansible.builtin.command: + argv: + - sysctl + - -p + - "{{ nftables_ip_forwarding_path }}" + removes: "{{ nftables_ip_forwarding_path }}" + become: true diff --git a/tasks/configuration.yml b/tasks/configuration.yml index 55cb9ec..f3696b0 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -18,3 +18,14 @@ mode: u=rw,g=,o= become: true notify: Restart nftables.service + +- name: Enable IP forwarding + ansible.builtin.template: + src: 100-ip_forwarding.conf.j2 + dest: "{{ nftables_ip_forwarding_path }}" + owner: root + group: root + mode: u=rw,g=r,o=r + when: nftables_ip_forwarding_path | length > 0 + become: true + notify: Enable 100-ip_forwarding.conf diff --git a/templates/100-ip_forwarding.conf.j2 b/templates/100-ip_forwarding.conf.j2 new file mode 100644 index 0000000..924a282 --- /dev/null +++ b/templates/100-ip_forwarding.conf.j2 @@ -0,0 +1,4 @@ +# {{ ansible_managed }} + +net.ipv4.conf.all.forwarding = 1 +net.ipv6.conf.all.forwarding = 1