Python2.7 yum 模块

Python2.7 yum 模块

我有一个运行 centos 5.8 的虚拟机,我刚刚安装了 python2.7,因为我遇到了一些问题import simplejson as json。安装 python2.7 并运行 ansible 角色后,出现以下错误:

failed: [default] => (item=httpd,httpd-devel) => {"failed": true, "item": "httpd,httpd-devel", "parsed": false}
invalid output was: SUDO-SUCCESS-jexgalzfpawatwlwldjlitpbyuyelqew
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-1391226441.99-18554377653196/yum", line 26, in <module>
    import yum
ImportError: No module named yum

我到处搜索 yum python 模块,但没能找到它。

有人能帮助我吗?

答案1

我找到了安装 python2.7 yum 模块的替代解决方案,该模块修复了我最初的错误import simplejosn as json。解决方案是在 ansible 之前包含一个 shell 配置,使用以下脚本安装旧版本的 simplejson(兼容)和 python2.4(可在 Centos 5.8 上使用):

#!/bin/sh
yum -y install wget
wget --no-check-certificate http://pypi.python.org/packages/source/s/simplejson/simplejson-2.0.9.tar.gz#md5=af5e67a39ca3408563411d357e6d5e47
tar xzvf simplejson-2.0.9.tar.gz
cd simplejson-2.0.9
sudo python setup.py install

答案2

我在新的虚拟环境中运行 ansible 时遇到了同样的问题。我的解决方案和你的一样,只是我使用 pip 将 simplejson 模块放在了正确的位置:

pip install simplejson==2.0.9

相关内容