Add role for ufw

This commit is contained in:
Ryan Cavicchioni 2024-04-14 18:32:50 -05:00
parent 7caf443b35
commit b45f8cf5dd
5 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
# ufw_state: enabled
# ufw_policy: allow
ufw_rules:
- port: ssh
rule: allow

View File

@ -0,0 +1,12 @@
---
- name: set ufw state
community.general.ufw:
state: "{{ ufw_state | default('enabled') }}"
policy: "{{ ufw_policy | default('allow') }}"
- name: configure rules
community.general.ufw:
port: "{{ item.port | default(omit) }}"
proto: "{{ item.proto | default(omit) }}"
rule: "{{ item.rule | default(omit) }}"
loop: "{{ ufw_rules | default([]) }}"

View File

26
roles/ufw/tasks/main.yaml Normal file
View File

@ -0,0 +1,26 @@
---
- name: gather OS specific variables
ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
vars:
params:
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- vars
- name: run os specific tasks
ansible.builtin.include_tasks: "{{ lookup('ansible.builtin.first_found', params) }}"
vars:
params:
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- tasks
- include_tasks: configure.yaml

View File