|
11 | 11 | shell: ssh -V 2>&1 | sed -r 's/.*_([0-9]*\.[0-9]).*/\1/g' |
12 | 12 | changed_when: false |
13 | 13 | register: sshd_version |
| 14 | + check_mode: no |
14 | 15 |
|
15 | 16 | - name: set hostkeys according to openssh-version |
16 | 17 | set_fact: |
17 | | - ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key'] |
18 | | - when: sshd_version.stdout >= '5.3' |
| 18 | + ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key'] |
| 19 | + when: sshd_version.stdout >= '6.3' and not ssh_host_key_files |
19 | 20 |
|
20 | 21 | - name: set hostkeys according to openssh-version |
21 | 22 | set_fact: |
22 | 23 | ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key'] |
23 | | - when: sshd_version.stdout >= '6.0' |
| 24 | + when: sshd_version.stdout >= '6.0' and not ssh_host_key_files |
24 | 25 |
|
25 | 26 | - name: set hostkeys according to openssh-version |
26 | 27 | set_fact: |
27 | | - ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key', '/etc/ssh/ssh_host_ed25519_key'] |
28 | | - when: sshd_version.stdout >= '6.3' |
| 28 | + ssh_host_key_files: ['/etc/ssh/ssh_host_rsa_key'] |
| 29 | + when: sshd_version.stdout >= '5.3' and not ssh_host_key_files |
| 30 | + |
| 31 | +- name: create revoked_keys and set permissions to root/600 |
| 32 | + template: src='revoked_keys.j2' dest='/etc/ssh/revoked_keys' mode=0600 owner="{{ ssh_owner }}" group="{{ ssh_group }}" |
| 33 | + notify: restart sshd |
| 34 | + when: ssh_server_hardening |
29 | 35 |
|
30 | 36 | - name: create sshd_config and set permissions to root/600 |
31 | 37 | template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner="{{ ssh_owner }}" group="{{ ssh_group }}" validate="/usr/sbin/sshd -T -f %s" |
|
57 | 63 |
|
58 | 64 | - block: # only runs when selinux is running |
59 | 65 | - name: install selinux dependencies when selinux is installed on RHEL or Oracle Linux |
60 | | - yum: name="{{item}}" state=installed |
| 66 | + package: name="{{item}}" state=installed |
61 | 67 | with_items: |
62 | 68 | - policycoreutils-python |
63 | 69 | - checkpolicy |
|
71 | 77 | when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' |
72 | 78 |
|
73 | 79 | - name: check if ssh_password module is already installed |
74 | | - shell: "semodule -l| grep ssh_password" |
| 80 | + shell: "semodule -l | grep ssh_password" |
75 | 81 | register: ssh_password_module |
76 | 82 | failed_when: false |
77 | 83 | changed_when: false |
|
99 | 105 |
|
100 | 106 | # The following tasks only get executed when selinux is in state enforcing, UsePam is "yes" and the ssh_password module is installed. |
101 | 107 | - name: remove selinux-policy when Pam is used, because Allowing sshd to read the shadow file directly is considered a potential security risk (http://danwalsh.livejournal.com/12333.html) |
102 | | - shell: semodule -r ssh_password |
| 108 | + command: semodule -r ssh_password |
103 | 109 | when: ssh_use_pam and ssh_password_module.stdout.find('ssh_password') == 0 |
104 | 110 |
|
105 | 111 | when: sestatus.rc == 0 |
0 commit comments