Skip to content

Commit 2ee20c7

Browse files
committed
make sshd config more flexible
1 parent 793fa69 commit 2ee20c7

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

ansible/roles/sshd/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Configure sshd.
55
## Role variables
66

77
- `sshd_password_authentication`: Optional bool. Whether to enable password login. Default `false`.
8+
- `sshd_conf_src`: Optional string. Path to sshd configuration template. Default is in-role template.
9+
- `sshd_conf_dest`: Optional string. Path to destination for sshd configuration file. Default is `/etc/ssh/sshd_config.d/10-ansible.conf` which overides `50-{cloud-init,redhat}` files, if present.

ansible/roles/sshd/defaults/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
sshd_password_authentication: false # Whether to enable password login
1+
sshd_password_authentication: false
2+
sshd_conf_src: sshd.conf.j2
3+
sshd_conf_dest: /etc/ssh/sshd_config.d/10-ansible.conf
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
- name: Configure SSH password authentication
1+
- name: Template sshd configuration
22
# NB: If parameters are defined multiple times the first value wins;
33
# The default /etc/ssh/sshd_config has
44
# Include /etc/ssh/sshd_config.d/*.conf
55
# early on, which is generally held to be the correct approach, so adding
66
# values to the end of that file won't work
7-
lineinfile:
8-
dest: /etc/ssh/sshd_config.d/10-ansible.conf # will beat 50-cloud-init and 50-redhat
9-
regexp: "^PasswordAuthentication"
10-
line: "PasswordAuthentication {{ 'yes' if sshd_password_authentication | bool else 'no' }}"
11-
state: present
12-
create: true
7+
template:
8+
src: "{{ sshd_conf_src }}"
9+
dest: "{{ sshd_conf_dest }}"
10+
owner: root
11+
group: root
12+
mode: u=rw,go=
1313
validate: sshd -t -f %s
1414
notify:
1515
- Restart sshd
16-
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# {{ ansible_managed }}
2+
PasswordAuthentication {{ 'yes' if sshd_password_authentication | bool else 'no' }}

0 commit comments

Comments
 (0)