Aborting, target uses selinux but python bindings (libselinux-python) aren’t installed

Audun Nes
Audun Nes
Sep 4, 2018 · 1 min read

The problem

When running Ansible in a Python virtual environment. Or when running molecule test, you encounter the following error:

Aborting, target uses selinux but python bindings (libselinux-python) aren’t installed!

The investigation

There are a couple of possible root causes for this:

  1. Maybe the error is right, and that libselinux-python is not installed.
  2. Python libraries for selinux are not available in a Python virtual environment.

The solution

To make sure libselinux-python is installed on Fedora:

sudo dnf install -y libselinux-python

To make sure libselinux-python is installed on CentOS:

sudo yum install -y libselinux-python

Imaging you have a virtual environment called ansible26, you first need to activate that virtual environment and then copy the Python libraries for selinux over:

workon ansible26cp -r /usr/lib64/python2.7/site-packages/selinux $VIRTUAL_ENVv/lib/python2.7/site-packagescp /usr/lib64/python2.7/site-packages/_selinux.so $VIRTUAL_ENVv/lib/python2.7/site-packages

Please note that workon is a command from https://virtualenvwrapper.readthedocs.io/ and if you haven’t installed virtualenvwrapper, you would rather navigate to your virtual environment directory, and then run:

source bin/activate

Credits to https://github.com/metacloud/molecule/issues/1209 where I found this solution.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade