-
Notifications
You must be signed in to change notification settings - Fork 3
/
playbook-sshd.yml
32 lines (27 loc) · 1.08 KB
/
playbook-sshd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
---
- hosts: all
become: true
become_user: root
become_method: sudo
tasks:
- name: do not allow root login via ssh
lineinfile: backrefs=yes state=present dest=/etc/ssh/sshd_config regexp="^PermitRootLogin yes" line="PermitRootLogin no"
notify: reload sshd
- name: do not allow password auth via ssh
lineinfile: backrefs=yes state=present dest=/etc/ssh/sshd_config regexp="#PasswordAuthentication yes" line="PasswordAuthentication no"
notify: reload sshd
- name: restrict listening interface
lineinfile:
state=present
dest=/etc/ssh/sshd_config
regexp="^ListenAddress {{ ansible_default_ipv4.address }}"
line="ListenAddress {{ ansible_default_ipv4.address }}"
when: ansible_default_ipv4.address != "127.0.0.1"
notify: reload sshd
handlers:
- name: reload sshd
service: name=sshd state=restarted enabled=true
when: ansible_distribution == 'CentOS'
- name: reload sshd
service: name=ssh state=restarted enabled=true
when: ansible_distribution == 'Ubuntu'