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