I'm trying to make ansible task that handles sshd_config properly. I've found similar regexp from other questions but they do nothing.
name: Disable SSH password authentication
become: true
lineinfile:
dest: /etc/ssh/sshd_config
regexp: '^#?\s*PasswordAuthentication\s'
line: 'PasswordAuthentication no'
state: present
Problem is it should handle duplicate lanes as well as comments. For example:
- There could be:
PasswordAuthentication no
PasswordAuthentication yes
or
PasswordAuthentication no
PasswordAuthentication no
or
PasswordAuthentication yes
PasswordAuthentication yes
or
PasswordAuthentication no
#PasswordAuthentication no
or
PasswordAuthentication no
# PasswordAuthentication no
or
# PasswordAuthentication no
# PasswordAuthentication no
etc so many combinations. But I just want to have single uncommented line PasswordAuthentication no
Is this possible?