ansible在centos5和centos6兼容性问题解决

ansible在centos5和centos6兼容性问题解决

1. 主控机推荐安装在centos6上,如果默认yum源没有ansible
推荐yum源
RHEL/CentOS 6:
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
RHEL/CentOS 7:
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2.安装ansible
yum -y install ansible

在主控机上执行ansible命令发现客户机为centos5版本的时候会报错,按照官方提示升级python版本,官方要求python版本不低于2.6,因为centos5 python默认在2.4.3。
以下为升级python版本的过程:

  1. 从python官网下载最新2.7.12版本: wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
  2. 解压:tar xzvf Python-2.7.12.tgz
  3. 编译安装三步骤:cd Python-2.7.12.tgz;./configue && make && make install
  4. 修改默认python:mv /usr/bin/python /usr/bin/pythonold;ln -s /usr/local/bin/python /usr/local/bin/python;
  5. 修改yum:vim /usr/bin/yum,修改第一行的python为python2.4
  6. 执行python -V : Python 2.7.12

经过上面的步骤以为自己大功告成,结果。。。。
在这里插入图片描述
仔细发现“object has no attribute 'decompressobj” 这个报错信息,检查是否缺少zlib
通过python import zlib
发现提示缺少该模块

这个时候发现有另外的centos5 同样安装的python2.7.12却又是可以实现ansible
在这里插入图片描述
两边的服务器一比较发现执行不成功的缺少zlib-devel,索性利用这点来试试看。。

这个时候发现在centos5上yum源已经失效,这个时候需要重新配置可用的yum源了。。。来吧 辛巴
因为各大网站已经撤了5的yum源,通过各大网站的readme文件提示新的都在http://vault.centos.org
贴上我的yum配置文件:

[base]
name=CentOS- r e l e a s e v e r − B a s e − 163. c o m b a s e u r l = h t t p : / / v a u l t . c e n t o s . o r g / 5.8 / o s / releasever - Base - 163.com baseurl=http://vault.centos.org/5.8/os/ releaseverBase163.combaseurl=http://vault.centos.org/5.8/os/basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5.8&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS- r e l e a s e v e r − U p d a t e s − 163. c o m b a s e u r l = h t t p : / / v a u l t . c e n t o s . o r g / 5.8 / u p d a t e s / releasever - Updates - 163.com baseurl=http://vault.centos.org/5.8/updates/ releaseverUpdates163.combaseurl=http://vault.centos.org/5.8/updates/basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5.8&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS- r e l e a s e v e r − E x t r a s − 163. c o m b a s e u r l = h t t p : / / v a u l t . c e n t o s . o r g / 5.8 / e x t r a s / releasever - Extras - 163.com baseurl=http://vault.centos.org/5.8/extras/ releaseverExtras163.combaseurl=http://vault.centos.org/5.8/extras/basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5.8&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS- r e l e a s e v e r − P l u s − 163. c o m b a s e u r l = h t t p : / / v a u l t . c e n t o s . o r g / 5.8 / c e n t o s p l u s / releasever - Plus - 163.com baseurl=http://vault.centos.org/5.8/centosplus/ releaseverPlus163.combaseurl=http://vault.centos.org/5.8/centosplus/basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS- r e l e a s e v e r − C o n t r i b − 163. c o m b a s e u r l = h t t p : / / v a u l t . c e n t o s . o r g / 5.8 / c o n t r i b / releasever - Contrib - 163.com baseurl=http://vault.centos.org/5.8/contrib/ releaseverContrib163.combaseurl=http://vault.centos.org/5.8/contrib/basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

注意:我这里已经直接把$releasever直接替换成了具体的版本号了
执行 yum clean all
执行 yum makecache

在centos5上执行 yum -y install zlib-devel
安装完成 执行ansible 发现还是一样的报错,并且python里面还是没有zlib模块。

索性删掉自己的编译安装的python2.7.12,重新编译安装!

再次执行:
在这里插入图片描述
大功告成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值