-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-ssh.yml
40 lines (37 loc) · 1.11 KB
/
configure-ssh.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
33
34
35
36
37
38
39
40
---
- name: "Configure ssh"
hosts: hosts_to_configure
become: yes
tasks:
- name: backup once
copy:
src: /etc/ssh/sshd_config
dest: /etc/ssh/sshd_config_backup_{{ansible_date_time.iso8601}}
owner: root
group: root
mode: '0644'
backup: yes
- name: Configure sshd
lineinfile:
path: "/etc/ssh/sshd_config"
regex: "^(#)?{{item.key}}"
line: "{{item.key}} {{item.value}}"
state: present
loop:
- { key: "AllowTcpForwarding", value: "no" }
- { key: "ClientAliveCountMax", value: "2" }
- { key: "Compression", value: "no" }
- { key: "GatewayPorts", value: "no" }
- { key: "LogLevel", value: "VERBOSE" }
- { key: "MaxAuthTries", value: "1" }
- { key: "MaxSessions", value: "2" }
- { key: "TCPKeepAlive", value: "no" }
- { key: "X11Forwarding", value: "no" }
- { key: "AllowAgentForwarding", value: "no" }
notify:
- restart sshd
handlers:
- name: restart sshd
ansible.builtin.service:
name: sshd
state: restarted