From c9bc611a128842b5dc7ae713f7bad4bfb2aef606 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 14 Oct 2022 15:24:28 +0200 Subject: try to copy initial sshd_config from /usr This is needed on OpenSUSE Tumbleweed ans has no effect if sshd_config is already present. --- tasks/main.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tasks') diff --git a/tasks/main.yml b/tasks/main.yml index 32ae5b1..4520020 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,25 @@ - name: Disable PasswordAuthentication + vars: + sshd_config_path: /etc/ssh/sshd_config tags: - ssh block: + - name: Check if sshd_config exists + ansible.buildin.stat: + path: '{{ sshd_config_path }}' + register: sshd_config_file + + - name: Copy initial sshd config + when: not sshd_config_file.stat.exists + ansible.builtin.copy: + src: /usr/etc/ssh/sshd_config + dest: '{{ sshd_config_path }}' + remote_src: true + mode: '640' + - name: Disable PasswordAuthentication in sshd config ansible.builtin.lineinfile: - path: /etc/ssh/sshd_config + path: '{{ sshd_config_path }}' regexp: "^[#]?\\s?PasswordAuthentication" line: "PasswordAuthentication no" register: disable_passwds -- cgit v1.2.3