Merge pull request 'feat/ufw_implementation' (#2) from feat/ufw_implementation into main

Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
2026-06-01 08:49:12 +00:00
3 changed files with 55 additions and 4 deletions

View File

@@ -1,11 +1,15 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/playbook.json
---
- name: Homelab alignment
hosts: online
hosts: managed
become: true
roles:
- role: repos
- role: common
- role: ufw
tags: ufw
- role: repos
tags: repos
- role: upgrade
tags: upgrade

View File

@@ -1,4 +1,5 @@
# roles/ufw/defaults/main.yml
---
ufw_default_incoming_policy: deny
ufw_default_outgoing_policy: allow
ufw_tailscale_interface: tailscale0
ufw_extra_rules: []

View File

@@ -0,0 +1,46 @@
---
# roles/ufw/tasks/main.yml
- name: Install UFW (Alpine)
community.general.apk:
name: ufw
state: present
update_cache: true
when: ansible_facts['os_family'] == "Alpine"
- name: Install UFW (Debian)
ansible.builtin.apt:
name: ufw
state: present
update_cache: true
when: ansible_facts['os_family'] == "Debian"
- name: Add UFW to default runlevel (Alpine)
ansible.builtin.command:
cmd: rc-update add ufw default
register: rc_update_result
changed_when: >- # ">- : transform multiple lines into one line"
'already' not in rc_update_result.stdout
and 'already' not in rc_update_result.stderr
failed_when: rc_update_result.rc != 0
when: ansible_facts['os_family'] == "Alpine"
- name: Set default incoming policy
community.general.ufw:
default: "{{ ufw_default_incoming_policy }}"
direction: incoming
- name: Set default outgoing policy
community.general.ufw:
default: "{{ ufw_default_outgoing_policy }}"
direction: outgoing
- name: Enable UFW
community.general.ufw:
state: enabled
- name: Allow all traffic on Tailscale interface
community.general.ufw:
rule: allow
interface: "{{ ufw_tailscale_interface }}"
direction: in