---
- name: Enable ufw
  become: yes
  ufw:
    state: enabled
    policy: allow
  tags:
    - firewall

- name: Allow OpenSSH
  become: yes
  ufw:
    rule: allow
    name: SSH
  tags:
    - firewall

- name: Allow Synergys
  become: yes
  ufw:
    rule: allow
    name: Synergy
  tags:
    - firewall

- name: Allow Steam Streaming
  become: yes
  ufw:
    rule: allow
    port: "{{ item.port }}"
    proto: "{{ item.proto }}"
  tags:
    - firewall
  with_items:
    - {port: 27031, proto: udp}
    - {port: 27036, proto: udp}
    - {port: 27036, proto: tcp}
    - {port: 27037, proto: tcp}
  when:
    - ansible_hostname == "firehouse"


---
- name: Reset all rules
  become: yes
  ufw:
    state: reset
  tags:
    - firewall

# Reject instead of deny
- name: Enable ufw
  become: yes
  ufw:
    state: enabled
    policy: reject
    logging: on
  tags:
    - firewall

- name: Allow OpenSSH
  become: yes
  ufw:
    rule: allow
    name: SSH
  tags:
    - firewall

- name: Ensure custom services are configured
  become: yes
  ufw:
    rule: "{{ item.rule|default('allow') }}"
    name: "{{ item.name }}"
  tags:
    - firewall
  with_items:
    - "{{ firewall_services }}"
  when:
    - firewall_services is defined

- name: Ensure custom ports are configured
  become: yes
  ufw:
    rule: "{{ item.rule|default('allow') }}"
    port: "{{ item.port }}"
    proto: "{{ item.proto }}"
    comment: "{{ item.comment|default(omit) }}"
  tags:
    - firewall
  with_items:
    - "{{ firewall_ports }}"
  when:
    - firewall_ports is defined

Reset ufw and configure services/ports from inventory
Reset ufw and configure services/ports from inventory
