Aborting, target uses selinux but python bindings (libselinux-python) aren’t installed
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:
- Maybe the error is right, and that libselinux-python is not installed.
- 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-pythonTo make sure libselinux-python is installed on CentOS:
sudo yum install -y libselinux-pythonImaging 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/activateCredits to https://github.com/metacloud/molecule/issues/1209 where I found this solution.