标签: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