码迷,mamicode.com
首页 > 其他好文 > 详细

import yum\r\nImportError: No module named yum

时间:2018-03-26 17:58:22      阅读:433      评论:0      收藏:0      [点我收藏+]

标签:ansible

报错: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   #修改第一行
......

import yum\r\nImportError: No module named yum

标签:ansible

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!