Skip to content

Commit 3aaf235

Browse files
authored
Use Include
@sjpb had a preference for using the same drop in pattern as Rocky 9 so that people can customize the template file
1 parent ce13394 commit 3aaf235

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

ansible/roles/sshd/tasks/configure.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
- name: Grab facts to determine distribution
2-
setup:
1+
- name: Ensure drop in directory exists
2+
file:
3+
path: /etc/ssh/sshd_config.d/*.conf
4+
state: directory
5+
owner: root
6+
group: root
7+
mode: 700
8+
become: true
9+
10+
- name: Ensure drop in directory is included
11+
lineinfile:
12+
dest: /etc/ssh/sshd_config
13+
regexp: "^Include /etc/ssh/sshd_config.d/*.conf"
14+
line: "Include /etc/ssh/sshd_config.d/*.conf"
15+
state: present
16+
insertafter: EOF
17+
validate: sshd -t -f %s
18+
notify:
19+
- Restart sshd
20+
become: true
321

422
- name: Template sshd configuration
523
# NB: If parameters are defined multiple times the first value wins;
@@ -16,16 +34,3 @@
1634
validate: sshd -t -f %s
1735
notify:
1836
- Restart sshd
19-
when: ansible_facts.distribution_major_version == '9'
20-
21-
- name: Disallow SSH password authentication
22-
lineinfile:
23-
dest: /etc/ssh/sshd_config
24-
regexp: "^PasswordAuthentication"
25-
line: "PasswordAuthentication {{ 'yes' if sshd_password_authentication | bool else 'no' }}"
26-
state: present
27-
validate: sshd -t -f %s
28-
notify:
29-
- Restart sshd
30-
become: true
31-
when: ansible_facts.distribution_major_version == '8'

0 commit comments

Comments
 (0)