diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-29 00:55:22 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-29 00:55:22 +0100 |
commit | 5b59f49bd64aec53fe109bc62fe821f469f8d95b (patch) | |
tree | 124c5ee3ff38cf4db132590dbfdfb4259be6a3b8 /ansible/roles/ufw/tasks/main.yml | |
parent | 9297d5731f8f069c719a9b8812a4fa92cd2a07c0 (diff) | |
download | infra-5b59f49bd64aec53fe109bc62fe821f469f8d95b.tar.gz infra-5b59f49bd64aec53fe109bc62fe821f469f8d95b.tar.bz2 infra-5b59f49bd64aec53fe109bc62fe821f469f8d95b.tar.xz infra-5b59f49bd64aec53fe109bc62fe821f469f8d95b.zip |
ufw: Adding reload and port forwardings (wip).
Diffstat (limited to 'ansible/roles/ufw/tasks/main.yml')
-rw-r--r-- | ansible/roles/ufw/tasks/main.yml | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/ansible/roles/ufw/tasks/main.yml b/ansible/roles/ufw/tasks/main.yml index b372eb7..0579f0a 100644 --- a/ansible/roles/ufw/tasks/main.yml +++ b/ansible/roles/ufw/tasks/main.yml @@ -2,20 +2,32 @@ - ufw become: yes block: - - when: ufw__nat_address is defined + - when: + notify: ufw reload blockinfile: path: /etc/ufw/before.rules insertbefore: "^# Don't delete these required lines" + marker: "# NAT config: {mark}" + state: "{{ 'present' if ufw__nat_address is defined else 'absent' }}" content: | - # NAT table rules *nat :POSTROUTING ACCEPT [0:0] - - # Forward traffic through eth0 - Change to match you out-interface -A POSTROUTING -s {{ ufw__nat_address }}/{{ ufw__nat_prefix }} -o eth0 -j MASQUERADE + COMMIT - # don't delete the 'COMMIT' line or these nat table rules won't - # be processed + - notify: ufw reload + vars: + forwardings: "{{ ufw__port_forwardings if ufw__port_forwardings is defined else [] }}" + blockinfile: + path: /etc/ufw/before.rules + insertbefore: "^# Don't delete these required lines" + marker: "# Port forwarding: {mark}" + state: "{{ 'present' if ufw__port_forwardings is defined else 'absent' }}" + content: | + *nat + {% for pf in forwardings %} + -A PREROUTING -i eth0 {{ " -d" + pf.addr if pf.addr is defined else "" }} -p {{ pf.proto if pf.proto is defined else "tcp" }} --dport {{ pf.port }} -j DNAT --to-destination {{ pf.to }}:{{ pf.to_port if pf.to_port is defined else pf.port }} + {% endfor %} COMMIT - ufw: |