1. 程式人生 > >import yum ImportError: No module named yum

import yum ImportError: No module named yum

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