import yum\r\nImportError: No module named yum

报错:FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.10.10 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_NDuf1p/ansible_module_yum.py\", line 27, in <module>\r\n import yum\r\nImportError: No module named yum\r\n", "msg": "MODULE FAILURE", "rc": 0}


报错原因,远程主机上默认的python版本为python2.7



解决方法:

1、在playbook中加入以下配置
vars:
ansible_python_interpreter: /usr/bin/python2.6
修改后的playbook如下:

- hosts: gitlab
  vars:
    ansible_python_interpreter: /usr/bin/python2.6.6
  become: True
  become_user: root
    gather_facts: false
  roles:    zabbix-agent

2、在ansible的hosts配置文件中添加ansible_python_interpreter参数为 python2.6

# vim /etc/ansible/hosts
[gitlab]
gitlab-server ansible_ssh_host=192.168.10.10 ansible_ssh_user=root ansible_python_interpreter=/usr/bin/python2.6.6   #添加最后字段

3、 修改 /usr/bin/yum 里为 旧的python解释器的路径即可

# vim /usr/bin/yum
#!/usr/bin/python2.6.6   #修改第一行
......

原文地址:http://blog.51cto.com/qiangsh/2091266

时间: 2024-10-31 09:49:33

import yum\r\nImportError: No module named yum的相关文章

python升级导致yum不可用 “ No module named yum”

最近在看python,虚拟机装的是Centos6.6,自带的python版本是2.6.6,打算升级到2.7. 我的升级过程大致如下: 下载2.7源码包https://www.python.org/downloads/source/ 卸载旧的python,rpm -e python 编译安装python2.7 整个过程没有遇到问题,但升级完后,再用yum安装软件时报如下错误 [[email protected] python]# yum There was a problem importing 

CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误

安装如下方法安装python2.7: yum install –y python27 python27-devel Python-docutils cd /usr/bin/ rm -rf python cp python2.7 python   出现yum错误:No module named yum 解决方法,查看 /usr/bin下python有哪几个版本 ll /usr/bin 我这里是:2.6  和  2.7 (刚安装的) 由于yum命令不兼容python2.7,需修改/usr/bin/y

python 升级到2.7.8 导致yum 运行异常:No module named yum

os version: [[email protected] etc]# cat redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga) ---运行yum 报错 [[email protected] ~]# yum install dialog There was a problem importing one of the Python modules required to run yum. The error

No module named yum解决办法

(1)错误提示: [[email protected] ~]# yum -y install kernel-debuginfo-common-2.6.18-238.el5 There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum Please install a package whi

No module named yum错误的解决办法

今天用yum安装软件的时候出现如下错误: There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum Please install a package which provides this module, or verify that the module is installed c

[linux]centos7 升级python后出现“No module named yum”错误

公司服务器重新安装系统后,手动升级python2.7.5到2.7.15,安装完python在更新系统python版本的过程中无意删除了系统自带的版本,导致后来在执行yum命令的时候出现了错误 There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum Please install a p

关于python3.X 报&quot;import urllib.request ImportError: No module named request&quot;错误,解决办法

#encoding:UTF-8 import urllib.request url = "http://www.baidu.com" data = urllib.request.urlopen(url).read() data = data.decode('UTF-8') print(data) 报错:import urllib.request ImportError: No module named request 解决办法: #encoding:UTF-8 import urlli

CentOS6.5运行yum报错:No module named yum

公司测试机环境不知道给我卸了什么包,导致yum运行报错状况: 报错情况: There was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was: No module named sqlite Please install a package which provides this module, orverify that the modu

centos7系统升级后yum update 出错No module named pycurl

Centos7升级后,运行yum update 结果如下 :]# yum updateThere was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was: No module named pycurl Please install a package which provides this module, orverify that th