Closed dschier-wtd closed 5 years ago
https://github.com/ansible/molecule/issues/1668 is related. /cc @ssbarnea
Yesterday I had a small chat in IRC #ansible-molecule
We came to the following workaround/solution:
# Create VENV
virtualenv --no-site-packages VENV
# Symlink system selinux packages + c-library
ln -s /usr/lib64/python3.7/site-packages/selinux/ VENV/lib/python3.7/site-packages/selinux
ln -s /usr/lib64/python3.7/site-packages/_selinux.cpython-37m-x86_64-linux-gnu.so VENV/lib/python3.7/site-packages/_selinux.cpython-37m-x86_64-linux-gnu.so
# Activate VENV
source ENV/bin/activate
# Install packages
pip install ansible molecule docker-py
Afterwards the VENV is usable. Maybe it can be added to the docs, that for some selinux systems it is needed to symlink the selinux libraries + the c-library.
@daniel-wtd Do not ever try to use "docker-py" package, is 4 years old, it was replaced by "docker". I woudl go so far to even request its removal from pypi and replacing it with a placeholder that installs docker one.
The root core issue here is different, is a design issue with molecule where by default it does hide the output when creation fails, something that is really common for new users and not only for new users.
I think we should find a way to address this and avoid the case where user needs to run again with --debug switch in order to find-out what went wrong. I would call it an unfortunate design decision, but we shoudl be able to find a way to address it.
@ssbarnea maybe the video from https://github.com/ansible/molecule/README.md leads to the opinion to use docker-py.
EDIT: it works woith docker-py and docker
The root cause here is not the docker package, but that the support for selinux is a little bit problematic. Using system-site-packages leads to problems and not using them forces to manual symlinking the selinux packages.
I think we should find a way to address this and avoid the case where user needs to run again with --debug switch in order to find-out what went wrong. I would call it an unfortunate design decision, but we shoudl be able to find a way to address it.
Just to link, I have a proposal out for an idea to fix this in https://github.com/ansible/molecule/issues/1666#issuecomment-454588682.
This problem is not limited to Fedora, is happening with CentOS too. I think it may prove to be a good enough reason to delay release of 2.20. The magic line is:
Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!
While trying to fix it I realised that we don't need to install libselinux into the container because the problem was with template module itself, cased by https://github.com/ansible/ansible/issues/34340
This is guaranteed to happen if you run tox on a redhat distro withotu sitespackages=true as libselinux bindings will be missing and there is no way to install them with pip.
Since Fedora has also some of the ansible packages in their repositories, it may happen, that sitepackages=true conflicts with the other python modules, already installed on the machine.
Is there a way, to import/link only selinux into the virtualenv?
@daniel-wtd what if you used tox --sitepackages
only if needed?
WRT linking just selinux
, I guess you could try symlinking or copying bindings to your virtualenv from system site-pakages as per https://dmsimard.com/2016/01/08/selinux-python-virtualenv-chroot-and-ansible-dont-play-nice/ AS LONG AS VENV'S PYTHON MATCHES THE SYSTEM ONE.
Other than that, the community could try putting together an OS-specific wheel dist compilation process to tackle the ability to do pip install libselinux
which would solve this in a more generic way.
Though, it would need to go to selinux upstream so that it could be kept up-to-date.
First use sitepackages does not cause conflicts because pip would remove syumlinked packages if they are not compatible and install compatible ones (newer or older).
The is still a very small risk which is more about the fact that other packages already installed on the system may become available during testing, for example pytest or flake8 plugins. In the past I had few cases where this caused different behavior during local testing, but it was easy to deal with it (they can be disabled in config).
Regarding installing libselinux inside virtualenvs, I know some workarounds but do really not want to go this route, involved doing manual file copy of the selinux module binaries from system into the virtualenv after creation. It is very specific to each distro/version and likely to break in so many cases... not to mention the additional ugliness added inside tox.ini
for performing these steps.
There are other reasons why we may want to use python system packages: for avoiding to compile binary modules like openssl.
PS. Yep, I asked about selinux binary, I am not sure is doable yet with current wheel. I know few projects had partial success with some libraries but with selinux it may be too specific to each disto and version to make it possible. Even so, we kinda need a fix "now".
for avoiding to compile binary modules like openssl.
All openssl wrappers I know already ship proper wheels. So it's not a good example.
Even so, we kinda need a fix "now".
Agreed. I can live with this now, but let's at least add more comprehensive comments there explaining the situation and downsides.
I made an update on the proposed change and also included a link to this bug, which will allow anyone that wonders about the resons behind to see the full discussion.
2019-03-13 IRC Meeting. Agreed this isn't 2.20 blocking
Will this be fixed and released into 2.20.2, or 2.21.0?
@Lirt This is not really molecule bug and it cannot eveb be attributed to Ansible, so is not really a priority to address it. Still you are welcomed to apply the workaround. If you are lucky simple installing selinux froom pypi may sort it for you.
I don't understand why I have selinux disabled on the CentOS 7.7 distros (on Azure) but Ansible when runs from local workstation says it's not installed so a docker_container module fails.
Why does it even require any selinux packages, when that one is disabled? o.O Is there some clean fix, or maybe will be, within Ansible future versions?
It looks like in these circumstances we have to revert to python 2.7, but we get warnings saying python 2.7 will be deprecated which is why I started to update everything and ran into this problem. We have to find all instances of yum and copy in playbooks and append this:
vars:
ansible_python_interpreter: "{{ package_python_interpreter }}"
Where package_python_interpreter is deifined as python2.7 for any centos 7 host. Finding these edge cases and overriding with host vars is a workaround, but not great.
I hope functions like and yum and copy will eventually work in python3 on Centos 7, before python 2.7 is deprecated.
Molecule and Ansible details
Molecule installation method (one of):
Ansible installation method (one of):
Detail any linters or test runners used:
Desired Behavior
molecule test
should run locally on Fedora 29 in virtualenvActual Behaviour
molecule test
brakes due to missing libselinux-python at StepCreate Dockerfiles from image names
Creating an env with site-packages is not able to perform due to pyyaml version. Creating an env without site packages is not able to perform due to missing selinux python bindings. Copying the selinux packages in the venv does not help.
Output of
molecule test
without site packages.Please feel free to reach out to me here or in IRC @freenode #ansible-molecule. I will do my best to support you.
Thanks a lot in advance!