Ansible and CentOS5

CentOS

How To Use Ansible for Centos 5 / RHEL 5

If running your playbooks with old CentOS/Rhel 5 hosts, it might ends with something like this:

"module_stdout": " File \".AnsiballZ_setup.py\", line 72\r\n with open(args_path, 'rb') as f:\r\n ^\r\nSyntaxError: invalid syntax\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1

The main problem is the python version, which by default is python 2.4. and requires to use Ansible <=2.3

Install older Ansible version on your manager host

Make sure you have virtualenv installed.

# dnf list installed python3-virtualenv

Then proceed with creating and activating the environment and finally installing Ansible <2.4

# virtualenv ansible2.3-env
# . ansible2.3-env/bin/activate
# pip install 'ansible==2.3.3.0'

A Python version <=3.6 is required for installing Ansible 2.3. If it fails, use a Python version available below 3.7.

# virtualenv -p /usr/bin/python2 ansible2.3-env
# virtualenv -p /usr/bin/python3.6 ansible2.3-env

Install python-simplejson on CentOS 5

Package "python-simplejson" is required on the host machines.

# yum install python-simplejson

Run playbook by using Ansible 2.3 on manager host

Finally you can try running your playbooks, by first activating the virtualenv and executing ansible-playbook.

Activate ansible 2.3 environment

# source ansible2.3-env/bin/activate

Make sure you are using the correct version

# ansible --version 

Run your playbook

# ansible-playbook some_playbook.yml

Previous Post Next Post