import yum\r\nImportError: No module named yum

前端之家收集整理的这篇文章主要介绍了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配置文件中,非python2.6环境服务器上添加ansible_python_interpreter参数

# 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、 如果yum命令执行失败,修改 /usr/bin/yum 里为 旧的python解释器的路径

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

猜你在找的Bash相关文章