Enable or Disable SELinux Boolean on Linux - Ansible module seboolean — Video Tutorial
How to automate the enabling of the "httpd_use_nfs" SELinux boolean and make it persistent after a reboot on Linux with Ansible.
Watch Video
Watch "Enable or Disable SELinux Boolean on Linux - Ansible module seboolean" on YouTube
What You'll Learn
- How to Enable or Disable SELinux Boolean on Linux with Ansible?
- SELinux Booleans
- Ansible Enable or Disable SELinux Boolean on Linux
- Parameters
- Links
- code
- execution
- idempotency
- before execution
- after execution
Full Tutorial Content
How to Enable or Disable SELinux Boolean on Linux with Ansible?
I'm going to show you a live Playbook with some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
SELinux Booleans
- SELinux boolean - changes how SELinux reacts
What is SELinux?
Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides a mechanism for supporting access control security policies, including mandatory access controls (MAC).
What are SELinux Booleans?
An SELinux boolean is a single string that changes how SELinux reacts.
You could find some examples in the following URL: https://www.redhat.com/sysadmin/change-selinux-settings-boolean
Ansible Enable or Disable SELinux Boolean on Linux
- ansible.posix.seboolean
- Toggles SELinux booleans
Today we're talking about Ansible module `seboolean`.
The full name is `ansible.posix.seboolean`, which means that is part of the collection of modules to interact with POSIX systems.
It's a module pretty stable and out for years, it toggles SELinux booleans.
It supports a huge variety of Linux distributions and POSIX systems.
It requires the `python3-libsemanage` or `libsemanage-python` package installed on the target system.
Parameters
- name string - The name of the boolean
- state boolean - no/yes
- persistent boolean - no/yes
- ignore_selinux_state boolean - no/yes
Let's see the parameter of the `seboolean` Ansible module.
The only mandatory parameters are "name" and "state".
The parameter "name" specifies the name of the SELinux boolean that we would like to modify.
The parameter "state" allows you to enable or disable the SELinux boolean immediately in the running system.
The parameter "persistent" allows you to specify if the state change is going to be applied to the next boot.
The special parameter "ignore_selinux_state" is useful for scenarios (chrooted environment) where you can't get the current SELinux state.
Links
- https://linux.die.net/man/8/apache_selinux
- https://www.redhat.com/sysadmin/change-selinux-settings-boolean
- https://wiki.gentoo.org/wiki/SELinux/Tutorials/Using_SELinux_booleans
- https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/using_selinux/index#adjusting-the-policy-for-sharing-nfs-and-cifs-volumes-using-selinux-booleans_configuring-selinux-for-applications-and-services-with-non-standard-configurations
## Playbook
Enable or Disable SELinux Boolean on Linux with Ansible Playbook.
code
```yaml
---
- name: seboolean module Playbook
hosts: all
become: true
vars:
selinux_boolean: "httpd_use_nfs"
selinux_value: true
tasks:
- name: package present
ansible.builtin.package:
name: "python3-libsemanage"
state: present
- name: set SELinux boolean
ansible.posix.seboolean:
name: "{{ selinux_boolean }}"
state: "{{ selinux_value }}"
persistent: true
```
execution
```bash
$ ansible-playbook -i virtualmachines/demo/inventory selinux/s
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 9 min
- Category: installation
Read the full written article: Enable or Disable SELinux Boolean on Linux - Ansible module seboolean
Topics Covered
Related Video Tutorials
- Ansible SELinux: Manage Modes, Booleans & Contexts (Complete Guide) — How to automate the enabling or disabling of SELinux Permissive policy per single process or domain keeping the whole system under enforcing policy and make it persistent after a reboot on Linux with Ansible.
- Set the SELinux Policy States and Modes on Linux - Ansible module selinux — How to automate the setting and verification of the "enforcing" SELinux mode and state with "targeted" policy and relabel the filesystem if necessary on Linux target with Ansible.
- Ansible code in RHSB-2021-009 Log4Shell - Remote Code Execution - log4j (CVE-2021-44228) — Learn how my Ansible Playbook was featured in Red Hat Security Bulletin RHSB-2021-009 to address the Log4Shell vulnerability (CVE-2021-44228). Discover the playbook and its role in mitigating security risks.
- Automate CIS Benchmark Hardening for RHEL 9 with Ansible — Discover how to automate CIS Benchmark hardening for RHEL 9 systems using Ansible. Simplify security compliance with the "ansible-lockdown" project for efficient, effective protection.
- Strengthening Security: Automating CIS Benchmark Hardening for RHEL 9 with Ansible — Automate CIS Benchmark hardening for RHEL 9 using Ansible with the Ansible Lockdown roles, ensuring robust security configurations across systems.
- Configuring Kernel Parameters in RedHat-like Linux Systems with Ansible System Role — Learn how to configure kernel parameters in RedHat-like Linux systems using the Ansible System Role. Follow our live Playbook example for efficient system management.