|
2 | 2 | - name: add the OS specific variables |
3 | 3 | include_vars: "{{ ansible_os_family }}.yml" |
4 | 4 |
|
5 | | -- name: check is selinux is installed |
6 | | - command: getenforce |
7 | | - register: selinux_installed |
8 | | - ignore_errors: true |
9 | | - changed_when: false |
10 | | - |
11 | 5 | - name: test to see if selinux is running |
12 | 6 | command: getenforce |
13 | 7 | register: sestatus |
14 | 8 | changed_when: false |
15 | | - when: selinux_installed.rc == 0 |
| 9 | + ignore_errors: true |
16 | 10 |
|
17 | 11 | - name: check the ssh_password policy state |
18 | 12 | shell: semodule -l | grep "ssh_password" | awk '{print $3}' |
19 | 13 | register: selinux_policy_state |
20 | | - when: selinux_installed.rc == 0 |
| 14 | + when: sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
21 | 15 | changed_when: false |
22 | 16 |
|
23 | 17 | - name: create sshd_config and set permissions to root/600 |
|
31 | 25 |
|
32 | 26 | - name: Create selinux custom policy drop folder |
33 | 27 | file: path={{ custom_selinux_dir }} state=directory owner=root group=root mode=0750 |
34 | | - when: not ssh_use_pam and sestatus.stdout != 'Disabled' and selinux_installed.rc == 0 |
| 28 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
35 | 29 |
|
36 | 30 | # The following tasks only get executed when selinux is in state enforcing and UsePam is "no". |
37 | 31 | # See this issue for more info: https://github.com/hardening-io/ansible-ssh-hardening/issues/23 |
38 | 32 |
|
39 | 33 | - name: Distributing custom selinux policies |
40 | 34 | copy: src='ssh_password' dest='{{ custom_selinux_dir }}' |
41 | 35 | register: custom_policies_output |
42 | | - when: not ssh_use_pam and sestatus.stdout != 'Disabled' and selinux_installed.rc == 0 |
| 36 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
43 | 37 |
|
44 | 38 | - name: check and compile policy |
45 | 39 | shell: checkmodule -M -m -o {{ custom_selinux_dir }}/ssh_password.mod {{ custom_selinux_dir }}/ssh_password |
46 | | - when: not ssh_use_pam and sestatus.stdout != 'Disabled' and selinux_installed.rc == 0 |
| 40 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
47 | 41 |
|
48 | 42 | - name: create selinux policy module package |
49 | 43 | shell: semodule_package -o {{ custom_selinux_dir }}/ssh_password.pp -m {{ custom_selinux_dir }}/ssh_password.mod |
50 | | - when: not ssh_use_pam and sestatus.stdout != 'Disabled' and selinux_installed.rc == 0 |
| 44 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
51 | 45 |
|
52 | 46 | - name: install selinux policy |
53 | 47 | shell: semodule -i {{ custom_selinux_dir }}/ssh_password.pp |
54 | | - when: not ssh_use_pam and sestatus.stdout != 'Disabled' and selinux_installed.rc == 0 |
| 48 | + when: not ssh_use_pam and sestatus.rc == 0 and sestatus.stdout != 'Disabled' |
55 | 49 |
|
56 | 50 | - 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) |
57 | 51 | shell: semodule -r ssh_password |
58 | | - when: (selinux_installed.rc == 0) and ssh_use_pam |
| 52 | + when: sestatus.rc == 0 and ssh_use_pam |
0 commit comments