Skip to content

Commit b878c0d

Browse files
authored
Merge pull request #992 from qdentity/fix-ufw-ssh-lockout
Fix ufw ssh lockout
2 parents e27ad09 + 60d84f4 commit b878c0d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

tasks/ufw.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@
7474
'deny (outgoing)' not in ufw_status.stdout or
7575
'disabled (routed)' not in ufw_status.stdout
7676
block:
77-
- name: Enable UFW service
78-
ansible.builtin.systemd_service:
79-
name: ufw
80-
enabled: true
81-
state: started
82-
when:
83-
- ansible_facts.virtualization_type not in ["container", "docker", "podman"]
77+
- name: Allow sshd port from administrator networks
78+
community.general.ufw:
79+
rule: "{{ 'limit' if ufw_rate_limit else 'allow' }}"
80+
from_ip: "{{ item.0 }}"
81+
to_port: "{{ item.1 | int }}"
82+
proto: tcp
83+
comment: ansible managed
84+
state: enabled
85+
loop: "{{ sshd_admin_net | product(sshd_ports) | list }}"
8486

8587
- name: Set default deny
8688
community.general.ufw:
@@ -94,6 +96,14 @@
9496
- incoming
9597
- outgoing
9698

99+
- name: Enable and start the UFW service
100+
ansible.builtin.systemd_service:
101+
name: ufw
102+
enabled: true
103+
state: started
104+
when:
105+
- ansible_facts.virtualization_type not in ["container", "docker", "podman"]
106+
97107
- name: Stat UFW rules
98108
become: true
99109
ansible.builtin.shell:
@@ -119,15 +129,6 @@
119129
when:
120130
- ufw_rate_limit
121131

122-
- name: Allow sshd port from administrator networks
123-
community.general.ufw:
124-
rule: limit
125-
from_ip: "{{ item.0 }}"
126-
to_port: "{{ item.1 | int }}"
127-
proto: tcp
128-
comment: ansible managed
129-
loop: "{{ sshd_admin_net | product(sshd_ports) | list }}"
130-
131132
- name: Allow outgoing specified ports
132133
community.general.ufw:
133134
rule: allow

0 commit comments

Comments
 (0)