Made ssh role more configurable and less repetitive
This commit is contained in:
4
roles/ssh/defaults/main.yml
Normal file
4
roles/ssh/defaults/main.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
sshd_x11_forwarding: false
|
||||||
|
sshd_password_auth: false
|
||||||
@@ -1,28 +1,15 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: Disable SSH root login without password
|
- name: Ensure sshd config options set correctly
|
||||||
lineinfile:
|
lineinfile:
|
||||||
path: /etc/ssh/sshd_config
|
path: /etc/ssh/sshd_config
|
||||||
regexp: '^#?PermitRootLogin .*$'
|
regexp: "^#?{{ item.key }} .*$"
|
||||||
line: "PermitRootLogin prohibit-password"
|
line: "{{ item.key }} {{ item.value }}"
|
||||||
state: present
|
state: present
|
||||||
validate: '/usr/sbin/sshd -t -f %s'
|
validate: '/usr/sbin/sshd -t -f %s'
|
||||||
notify: restart ssh
|
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user