Skip to content

Instantly share code, notes, and snippets.

@andreacarriero
Created February 28, 2018 19:25
Show Gist options
  • Save andreacarriero/1b5adcde61906fb5c6342bfa88ceeb0c to your computer and use it in GitHub Desktop.
Save andreacarriero/1b5adcde61906fb5c6342bfa88ceeb0c 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