1

We have some 50 odd linux 5 hosts, and to manage that we use ansible.

Problem :- Ansible modules copy/template errors for Linux 5 hosts using python26 ,python binding libselinux-python needed

Actual error :- fatal : FAILED! => {"changed": false, "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}

Environment:-

Ansible Master node : - EL7
Selinux enabled
libselinux-python : installed libselinux-python.x86_64 0:2.5-14.1.el7

Node :- EL 5
Selinux enabled
Using ansible_python_interpreter=/usr/bin/python26
libselinux-python : installed libselinux-python-1.33.4-5.7.el5.x86_64

Description:-

I see the problem

With default Python ...

selinux]# python
Python 2.4.3 (#1, May 5 2011, 15:12:27)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import selinux
selinux.is_selinux_enabled()
1

And with python26

[root@dev-bozo21 selinux]# python26
Python 2.6.8 (unknown, Nov 7 2012, 14:47:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import selinux
Traceback (most recent call last):
File "", line 1, in 
ImportError: No module named selinux

I tried copying

"/usr/lib64/python2.4/site-packages/selinux to /usr/lib64/python2.6/site-packages/selinux ( this was empty earlier)"

it throws this error

python26
Python 2.6.8 (unknown, Nov 7 2012, 14:47:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import selinux
Traceback (most recent call last):
File "", line 1, in 
File "/usr/lib64/python2.6/site-packages/selinux/init.py", line 5, in 
import _selinux
ImportError: /usr/lib64/python2.6/site-packages/selinux/_selinux.so: undefined symbol: Py_InitModule4

And when copying

"/usr/lib64/python2.7/site-packages/selinux/init.py" ( from different centos 7 node) to /usr/lib64/python2.6/site-packages/selinux/

I get below error

python2.6
Python 2.6.8 (unknown, Nov 7 2012, 14:47:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import selinux
Traceback (most recent call last):
File "", line 1, in 
File "/usr/lib64/python2.6/site-packages/selinux/init.py", line 26, in 
_selinux = swig_import_helper()
File "/usr/lib64/python2.6/site-packages/selinux/init.py", line 22, in swig_import_helper
_mod = imp.load_module('_selinux', fp, pathname, description)
ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/python2.6/site-packages/selinux/_selinux.so)

Any solution for this problem ?

3
  • 1
    I voted - 1 for the question having an error in English suggesting a solution that the OP overlooked. Mar 22, 2019 at 5:01
  • Thats pretty harsh :) Mar 22, 2019 at 6:12
  • Not harsh; pragmatic. It gave you the solution, and you acknowledged you saw the solution. This question isn't about ansible failing. It's about the python version on your node missing libraries/functions.
    – 0xSheepdog
    Mar 27, 2019 at 18:04

3 Answers 3

2

I literally ran into this problem on a few hosts in my infrastructure today.

The solution is to do what the error says. Install the libselinux-python package. Or you could disable selinux on the target host(s).

From the Ansible website:

If you have SELinux enabled on remote nodes, you will also want to install libselinux-python on them before using any copy/file/template related functions in Ansible. You can of course still use the yum module in Ansible to install this package on remote systems that do not have it.

7
  • I do have libselinux-python installed in the node , But looks like it is bound with python2.4 , selinux module doesnt seem be there for python26. Mar 22, 2019 at 6:11
  • And disabling SELINUX is not something we are looking into currently. Mar 22, 2019 at 6:44
  • 1
    @PrakashSharma: Different versions of python require different versions of libraries. Install libselinux-python for python 2.6.
    – Peschke
    Mar 22, 2019 at 7:06
  • I thought for that , but couldn't find anything for python26 . On Linux 5 , I see this is the only package available libselinux-python-1.33.4-5.7.el5. No later version from that. Mar 22, 2019 at 7:12
  • 1
    Copying modules/libraries for one definitive version of python into the folders of another version is not exactly best practice. I see two possible solutions; find what provides the libselinux-python files necessary for python2.6, or find another way to do this (without ansible?) With EL5 you are going to find limited support with modern orchestration tools like Ansible.
    – 0xSheepdog
    Mar 27, 2019 at 18:01
1

I simply run this and it solved my problem

yum install libselinux-python3
1

As already said the solution is install libselinux-python3. To be more exact though libselinux-python3 needs to be installed on each host machine, not the ansible server.

To ensure that the library was installed on every host I added an extra line to install libselinux-python3 before I run any of the modules dependent on it.

- name: install python selinux library required by future ansible modules
  become: true
  yum:
    name: libselinux-python3
    state: present
    update_cache: true

this fixed my later commands that were previously failing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .