How Do You Troubleshoot Ansible Errors about SELinux?

Problem scenario
You have Python 3 installed, but you do not have pip3 installed. One of the following also apply to your situation:

Problem scenario #1
You run an Ansible playbook. You receive the error message "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed."

Problem scenario #2
You run an Ansible playbook. You receive the error message "module 'selinux' has no attribute 'is_selinux_enabled'".

What should you do?

Solution
Assuming you pip has been installed, do the following:

1. Run this command (where /path/to is the directory path to where pip is installed):
sudo /path/to/pip install --upgrade pip

2. Run this command:

sudo pip3 install selinux

You are done.

If you cannot install pip (and it is not installed), see this posting How Do You Get the libselinux-python to Work with Python 3?.

Leave a comment

Your email address will not be published. Required fields are marked *