Disable SSH password auth in the common role only when sshd is active

This commit is contained in:
2026-10-09 14:37:24 +00:00
parent 13d60c4f9b
commit 6390e6288b
+19 -11
View File
@@ -1,12 +1,20 @@
- name: Disable SSH password auth - name: Check if SSH daemon is active
lineinfile: systemd:
dest: /etc/ssh/sshd_config name: sshd
regexp: '^PasswordAuthentication\s*yes' state: started
line: "PasswordAuthentication no" register: sshd_status
register: sshd_config
- name: Restart SSH daemon - block:
service: - name: Disable SSH password auth
name: sshd lineinfile:
state: restarted dest: /etc/ssh/sshd_config
when: sshd_config.changed regexp: '^PasswordAuthentication\s*yes'
line: "PasswordAuthentication no"
register: sshd_config
- name: Restart SSH daemon
service:
name: sshd
state: restarted
when: sshd_config.changed
when: sshd_status.status.ActiveState == 'active'