How To Use Ansible For Centos 5 / RHEL 5

Published on Author gryzli

If you try to run some of your playbooks over old Centos/Rhel 5 host, you might be ending with weird message like this:

{"changed": false, "module_stderr": " File \"<stdin>\", line 39\n with open(module, 'wb') as f:\n ^\nSyntaxError: invalid syntax\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Without going into too much detail, there is a problem when you try to use newer Ansible versions with older hosts or more precise hosts with older python version.

The main problem of operating Centos 5 is the python version, which by default is python 2.4. The problem is applicable to any other operating system using old python version.

 

Solution – Use older Ansible version, that works with python 2.4

 

1) Install older Ansible version on your manager host

Before you proceed, make sure you have “virtualenv” installed.

In order to not screw up your current Ansible installation, this could be achieved by using virtualenv, which is pretty handy.

 

2) Install python-simplejson on your Centos 5 machines

You will need the package “python-simplejson” installed on your host machines (the ones you are going to orchestrate).

This is as easy as executing:

 

3) 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.

 

Some More Ansible Resources I’ve Written

Optimizing Ansible for Maximum Performance

Print All Variables in Ansible

Dump All Variables In Ansible

Ansible CheatSheet