Skip to content

Commit

Permalink
fix: Use ignore_selinux_state module option
Browse files Browse the repository at this point in the history
It is possible to configure SELinux on nodes with SELinux disabled
before they're switch to permissive/enforcing. The only requirement is
that targeted SELinux policy (or a policy configured in
/etc/selinux/config) needs to be installed.

It's also necessary to use seboolean module with `persistent: true` when
SELinux is disabled.

Fixes: #188

Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
  • Loading branch information
bachradsusi committed Oct 3, 2023
1 parent 6e4b122 commit 7e27e0c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
seboolean:
name: "{{ item.name }}"
state: "{{ item.state }}"
persistent: "{{ item.persistent | default('no') }}"
persistent: "{{ item.persistent |
default( ansible_selinux.status == 'disabled' ) }}"
ignore_selinux_state: "{{ ansible_selinux.status == 'disabled' }}"
with_items: "{{ selinux_booleans }}"

- name: Set SELinux file contexts
Expand All @@ -79,6 +81,7 @@
state: "{{ item.state | default('present') }}"
selevel: "{{ item.selevel | default(omit) }}"
seuser: "{{ item.seuser | default(omit) }}"
ignore_selinux_state: "{{ ansible_selinux.status == 'disabled' }}"
with_items: "{{ selinux_fcontexts }}"

- name: Restore SELinux labels on filesystem tree
Expand All @@ -102,6 +105,7 @@
setype: "{{ item.setype }}"
state: "{{ item.state | default('present') }}"
local: "{{ item.local | default(False) }}"
ignore_selinux_state: "{{ ansible_selinux.status == 'disabled' }}"
with_items: "{{ selinux_ports }}"

- name: Set linux user to SELinux user mapping
Expand All @@ -111,6 +115,7 @@
serange: "{{ item.serange | default('s0') }}"
state: "{{ item.state | default('present') }}"
reload: "{{ item.reload | default(False) }}"
ignore_selinux_state: "{{ ansible_selinux.status == 'disabled' }}"
with_items: "{{ selinux_logins }}"
notify: __selinux_reload_policy

Expand Down

0 comments on commit 7e27e0c

Please sign in to comment.