It's been quite sometime since I blogged. So, I thought, well, it should be something that helps all the folks and not just Oracle DBAs.
I have been dabbling a bit with Ansible, Python and Oracle database for a few automation tasks. During this process, I did face issues with making Ansible 2.7 work with OEL/RHEL 5.
As
you all know, with the release of Ansible 2.4, the minimum version of
Python required on the remote nodes is >= 2.6.
However, with
OEL/RHEL 5, the default version of Python is 2.4.
So, if you are still wondering how to make the two to tango , here goes:
1. Download the latest version of Python 2.7 from here.
NOTE: At the time of writing this blog, Python 2.7.16 was the latest Python 2.7 version downloadable from here.
2. Ensure rpms zlib and
zlib-devel are installed on the target node.
#
rpm -qa | grep zlib
NOTE:
If zlib-devel isn't installed, we'll get the below error:
myserver.domain.com |
FAILED! => {
"changed": false,
"module_stderr": "Shared
connection to myserver.domain.com closed.\r\n",
"module_stdout": "Traceback
(most recent call last):\r\n File
\"/oracle/home/oracle/.ansible/tmp/ansible-tmp-1540898245.08-275033388982084/AnsiballZ_ping.py\",
line 113, in \r\n
_ansiballz_main()\r\n File
\"/oracle/home/oracle/.ansible/tmp/ansible-tmp-1540898245.08-275033388982084/AnsiballZ_ping.py\",
line 105, in _ansiballz_main\r\n
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File
\"/oracle/home/oracle/.ansible/tmp/ansible-tmp-1540898245.08-275033388982084/AnsiballZ_ping.py\",
line 40, in invoke_module\r\n
f.write(z.read('__main__.py'))\r\n
File \"/opt/python2.7/lib/python2.7/zipfile.py\", line 931, in
read\r\n return self.open(name,
\"r\", pwd).read()\r\n File
\"/opt/python2.7/lib/python2.7/zipfile.py\", line 1006, in open\r\n close_fileobj=should_close)\r\n File
\"/opt/python2.7/lib/python2.7/zipfile.py\", line 526, in
__init__\r\n self._decompressor = zlib.decompressobj(-15)\r\nAttributeError:
'NoneType' object has no attribute 'decompressobj'\r\n",
"msg": "MODULE FAILURE\nSee
stdout/stderr for the exact error",
"rc": 1
2. https://unix.stackexchange.com/questions/164517/nonetype-object-has-no-attribute-decompressobj-while-installing-bootstrap-se
3. Untar and unzip Python gzip tar file on the remote node.
# cd /tmp
# tar xzvf /tmp/Python-2.7.16.tgz
4. Configure Python for alternate path as below:
#
cd /tmp/Python-2.7.16; ./configure --prefix=/opt/python2.7 --enable-shared
5. Use make executable to "make" the Python folder:
#
cd /tmp/Python-2.7.16; make
6. Use make altinstall to create the alternate Python:
#
cd /tmp/Python-2.7.16; make altinstall
7. Now, create a shell script under
$HOME (home directory) of oracle os user (or any other user that'll be used for ansible), on the target node:
$ cat ~/python_exec.sh
#!/bin/bash
export
LD_LIBRARY_PATH="/opt/python2.7/lib":$LD_LIBRARY_PATH
exec /opt/python2.7/bin/python2.7 "$@"
$ ls -lrt ~/python_exec.sh
-rwxr-xr-x 1 myuser mygroup 113 Jul 1 04:31 python_exec.sh
NOTE: This is to avoid the below error:
$ ansible myremoteserver.domain.com -i
inv -u oracle -m ping
myremoteserver.domain.com |
FAILED! => {
"changed": false,
"module_stderr": "Shared
connection to myremoteserver.domain.com closed.\r\n",
"module_stdout":
"/opt/python2.7/bin/python2.7: error while loading shared libraries:
libpython2.7.so.1.0: cannot open shared object file: No such file or
directory\r\n",
"msg": "MODULE FAILURE\nSee
stdout/stderr for the exact error",
"rc": 127
}
8. Now, either in host_vars or in group_vars (depends entirely upon you), define the python interpreter as below:
ansible_python_interpreter: ~/python_exec.sh
9. et voilĂ ! ansible 2.7 works like a charm with OEL/RHEL 5.
$ ansible mytargetserver.domain.com -i hosts -m pingmytargetserver.domain.com | SUCCESS => {
"changed": false,
"ping": "pong"
}
Comments