Made ssh role more configurable and less repetitive

This commit is contained in:
uumas
2022-01-07 21:49:59 +02:00
parent 04d03e71ba
commit 0e07a1e2b3
2 changed files with 11 additions and 20 deletions

View File

@@ -1,28 +1,15 @@
---
- name: Disable SSH root login without password
- name: Ensure sshd config options set correctly
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?PermitRootLogin .*$'
line: "PermitRootLogin prohibit-password"
regexp: "^#?{{ item.key }} .*$"
line: "{{ item.key }} {{ item.value }}"
state: present
validate: '/usr/sbin/sshd -t -f %s'
notify: restart ssh
with_dict:
PermitRootLogin: 'prohibit-password'
PasswordAuthentication: "{{ 'yes' if sshd_password_auth else 'no' }}"
X11Forwarding: "{{ 'yes' if sshd_x11_forwarding else 'no' }}"
- name: Disable PasswordAuthentication
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#PasswordAuthentication .*$'
line: "PasswordAuthentication no"
state: present
validate: '/usr/sbin/sshd -t -f %s'
notify: restart ssh
- name: Disable X11 forwarding
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?X11Forwarding .*$'
line: "X11Forwarding no"
state: present
validate: '/usr/sbin/sshd -t -f %s'
notify: restart ssh