Skip to content

Instantly share code, notes, and snippets.

@MagedSaeed
Forked from andreacarriero/setup_firewall.yml
Created July 7, 2022 14:19
Show Gist options
  • Save MagedSaeed/3d0b00ee615eed09177a6f2e0fd19bef to your computer and use it in GitHub Desktop.
Save MagedSaeed/3d0b00ee615eed09177a6f2e0fd19bef to your computer and use it in GitHub Desktop.
[Ansible Playbook] Setup UFW to allow only incoming ssh connections
---
- hosts: all
become: true
tasks:
- name: ensure ufw installed
apt: name=ufw update_cache=true
- name: ufw deny incoming
ufw:
direction: incoming
proto: any
policy: deny
notify:
- reload ufw
- name: ufw allow outgoing
ufw:
direction: outgoing
proto: any
policy: allow
notify:
- reload ufw
- name: ufw allow ssh
ufw:
rule: allow
name: OpenSSH
notify:
- reload ufw
- name: enable ufw service
ufw:
state: enabled
handlers:
- name: reload ufw
ufw:
state: reloaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment