Still have to keep some CentOS5 hosts, they have yum configured to use CentOS vault repo like this https://hastebin.com/ojopevanas.ini. That works fine when use yum there on host.
When however I try to use ansible for that, like:
- name: "Install OS packages"
yum: pkg={{item}} state=installed
with_items:
- dos2unix
- vim
I get "msg": "python2 bindings for rpm are needed for this module. python2 yum module is needed for this module"
NOTE: the host has python26 installed next to default24
in the inventory file hostname has ansible_python_interpreter=/usr/bin/python26 next to it (otherwise ansible cannot even -m ping). Other ansible tasks works fine with this host
The yum
module requires the rpm
Python module, which is provided by the rpm-python
package. On your system, this is installed for Python 2.4; you haven't installed it for Python 2.6. This is a binary module that must be compiled from source (it is part of the rpm distribution).
If you need to support CentOS 5, the easiest solution is probably to use the command
module in lieu of the yum
module:
- name: "Install OS packages"
command: "yum install -y -e0 -d2 {{item}}"
with_items:
- dos2unix
- vim
Since issue does not look easily resolvable with native yum: module of ansible, this is how I made it work:
- block:
- debug: msg="Special actions for centos 5, vault and epel repo"
- copy:
src: "CentOS-Vault.repo"
dest: /etc/yum.repos.d/CentOS-Vault.repo
- copy:
src: "epel-release-5-4.noarch.rpm"
dest: /tmp/epel-release-5-4.noarch.rpm
- shell: "rpm -ivh /tmp/epel-release-5-4.noarch.rpm"
ignore_errors: true
register: epelrpmres
changed_when: "'is already installed' not in epelrpmres.stderr"
- shell: >
yum --disablerepo=* --enablerepo=C5*,epel* -y install
dos2unix moreutils vim-minimal vim-enhanced tmux tcping
rsync openssh-clients htop screen tar
register: yumresult
changed_when: "'Nothing to do' not in yumresult.stdout"
when: "ansible_distribution_major_version in ['5']"
In the hope this will help anybody else ...