- name: Install UFW
  apt:
    name: ufw
    state: present

- name: Deny all traffic by default
  ufw:
    state: enabled
    policy: deny

- name: Allow SSH traffic
  ufw:
    rule: allow
    port: ssh

- name: Allow traffic to custom ports
  ufw:
    rule: allow
    port: "{{ item.value.port }}"
    proto: "{{ item.value.proto }}"
  with_dict: "{{ ufw_enabled_ports }}"

- name: Install UFW
  apt:
    name: ufw
    state: present

- name: Deny all traffic by default
  ufw:
    state: enabled
    policy: deny
    direction: incoming

- name: Allow SSH traffic
  ufw:
    rule: allow
    port: ssh

- name: Allow traffic to custom ports
  ufw:
    rule: allow
    port: "{{ item.value.port }}"
    proto: "{{ item.value.proto }}"
  with_dict: "{{ ufw_enabled_ports }}"

Update for new UFW versions.
Update for new UFW versions.

The default policy now requires a direction.
