add win_firewall role
This commit is contained in:
58
roles/win_firewall/README.md
Normal file
58
roles/win_firewall/README.md
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
win_firewall
|
||||||
|
=========
|
||||||
|
|
||||||
|
Configure windows hosts as a Spoke in the Wireguard Spoke-and-Hub topology.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
win_firewall_name: name # Required
|
||||||
|
|
||||||
|
# Default variables
|
||||||
|
win_firewall_action: allow
|
||||||
|
win_firewall_direction: in
|
||||||
|
win_firewall_enabled: true
|
||||||
|
win_firewall_localip: any
|
||||||
|
win_firewall_localport: any
|
||||||
|
win_firewall_profiles: domain,private,public
|
||||||
|
win_firewall_program: any
|
||||||
|
win_firewall_protocol: any
|
||||||
|
win_firewall_remoteip: any
|
||||||
|
win_firewall_remoteport: any
|
||||||
|
win_firewall_service: any
|
||||||
|
win_firewall_state: present
|
||||||
|
```
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
ansible.windows
|
||||||
|
community.windows
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
roles:
|
||||||
|
- role: genlab.common.win_firewall
|
||||||
|
win_firewall_name: Allow port 1234 to 10.0.0.0/24
|
||||||
|
win_firewall_action: allow
|
||||||
|
win_firewall_localport: 1234
|
||||||
|
win_firewall_remoteip: 10.0.0.0/24
|
||||||
|
```
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
malyuk.ss@genlab.llc
|
||||||
13
roles/win_firewall/defaults/main.yml
Normal file
13
roles/win_firewall/defaults/main.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
win_firewall_action: allow
|
||||||
|
win_firewall_direction: in
|
||||||
|
win_firewall_enabled: true
|
||||||
|
win_firewall_localip: any
|
||||||
|
win_firewall_localport: any
|
||||||
|
win_firewall_profiles: domain,private,public
|
||||||
|
win_firewall_program: any
|
||||||
|
win_firewall_protocol: any
|
||||||
|
win_firewall_remoteip: any
|
||||||
|
win_firewall_remoteport: any
|
||||||
|
win_firewall_service: any
|
||||||
|
win_firewall_state: present
|
||||||
1
roles/win_firewall/handlers/main.yml
Normal file
1
roles/win_firewall/handlers/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
16
roles/win_firewall/meta/main.yml
Normal file
16
roles/win_firewall/meta/main.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
galaxy_info:
|
||||||
|
role_name: "win_firewall"
|
||||||
|
namespace: genlab
|
||||||
|
author: "Sergey Malyuk"
|
||||||
|
company: "Genlab, LLC"
|
||||||
|
description: "Configures clean windows firewall"
|
||||||
|
license: "MIT"
|
||||||
|
min_ansible_version: "2.16"
|
||||||
|
|
||||||
|
platforms:
|
||||||
|
- name: "Windows"
|
||||||
|
|
||||||
|
galaxy_tags: []
|
||||||
|
|
||||||
|
dependencies: []
|
||||||
9
roles/win_firewall/molecule/default/converge.yml
Normal file
9
roles/win_firewall/molecule/default/converge.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
pre_tasks:
|
||||||
|
# Blank task for ignoring CI testing
|
||||||
|
# This role was tested manually
|
||||||
|
- name: Blank
|
||||||
|
ansible.builtin.command: echo
|
||||||
|
changed_when: false
|
||||||
22
roles/win_firewall/molecule/default/molecule.yml
Normal file
22
roles/win_firewall/molecule/default/molecule.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
platforms:
|
||||||
|
- name: ubuntu
|
||||||
|
image: geerlingguy/docker-ubuntu2204-ansible:latest
|
||||||
|
pre_build_image: true
|
||||||
|
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
|
cgroupns_mode: host
|
||||||
|
privileged: true
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
verifier:
|
||||||
|
name: ansible
|
||||||
|
lint: |
|
||||||
|
set -e
|
||||||
|
yamllint .
|
||||||
|
ansible-lint .
|
||||||
11
roles/win_firewall/molecule/default/verify.yml
Normal file
11
roles/win_firewall/molecule/default/verify.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Verify
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
# Blank task for ignoring CI testing
|
||||||
|
# This role was tested manually
|
||||||
|
- name: Blank
|
||||||
|
ansible.builtin.command: echo
|
||||||
|
changed_when: false
|
||||||
50
roles/win_firewall/tasks/main.yml
Normal file
50
roles/win_firewall/tasks/main.yml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
- name: Print out rule name for convenient debugging
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ win_firewall_name }}"
|
||||||
|
|
||||||
|
- name: Check if firewall is configured
|
||||||
|
block:
|
||||||
|
- name: Get firewall flag stat
|
||||||
|
ansible.windows.win_stat:
|
||||||
|
path: C:\firewall.flag
|
||||||
|
register: win_firewall_firewall_flag
|
||||||
|
|
||||||
|
- name: Assert that firewall.flag exists
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: win_firewall_firewall_flag.stat.exists
|
||||||
|
success_msg: "firewall.flag exists"
|
||||||
|
fail_msg: "firewall.flag DOES NOT exist"
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
- name: Disable Windows Firewall
|
||||||
|
ansible.windows.win_firewall:
|
||||||
|
state: disabled
|
||||||
|
|
||||||
|
- name: Delete all firewall rules
|
||||||
|
ansible.windows.win_shell: netsh advfirewall firewall delete rule name=all
|
||||||
|
|
||||||
|
- name: Create firewall.flag
|
||||||
|
ansible.windows.win_file:
|
||||||
|
path: C:\firewall.flag
|
||||||
|
state: touch
|
||||||
|
|
||||||
|
- name: Create firewall rule
|
||||||
|
community.windows.win_firewall_rule:
|
||||||
|
name: "{{ win_firewall_name }}"
|
||||||
|
action: "{{ win_firewall_action }}"
|
||||||
|
direction: "{{ win_firewall_direction }}"
|
||||||
|
enabled: "{{ win_firewall_enabled }}"
|
||||||
|
localip: "{{ win_firewall_localip }}"
|
||||||
|
localport: "{{ win_firewall_localport }}"
|
||||||
|
profiles: "{{ win_firewall_profiles }}"
|
||||||
|
program: "{{ win_firewall_program }}"
|
||||||
|
protocol: "{{ win_firewall_protocol }}"
|
||||||
|
remoteip: "{{ win_firewall_remoteip }}"
|
||||||
|
remoteport: "{{ win_firewall_remoteport }}"
|
||||||
|
service: "{{ win_firewall_service }}"
|
||||||
|
state: "{{ win_firewall_state }}"
|
||||||
|
|
||||||
|
- name: Enable Windows Firewall
|
||||||
|
ansible.windows.win_firewall:
|
||||||
|
state: enabled
|
||||||
1
roles/win_firewall/vars/main.yml
Normal file
1
roles/win_firewall/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
Reference in New Issue
Block a user