在流浪者的Ansible错误中没有模块名称Yum

时间:2016-10-18 16:52:10

标签: vagrant ansible yum

我在Ubuntu Vagrant机器上尝试使用Ansible剧本进行了一些实验。我写了一个名为exampleyum.yml的简单剧本如下:

---
- hosts: local

  tasks:
    - name: Installing packages
      yum: name=httpd state=latest
      sudo: yes

当我跑步时

ansible-playbook -i ~/inventory.ini exampleyum.yml

我收到以下错误:

  

任务执行期间发生异常。看到满满的   回溯,使用-vvv。错误是:ImportError:没有名为yum的模块   致命:[localhost]:失败! => {“已更改”:false,“failed”:true,   “module_stderr”:“Traceback(最近一次调用最后一次):\ n文件   \“/ tmp / ansible_qeXrGO / ansible_module_yum.py \”,第25行,\ n   import yum \ nImportError:没有名为yum \ n“,”module_stdout“:”“的模块,   “msg”:“MODULE FAILURE”}

它会导致一些导入错误和模块故障。我在某处读到Yum是核心模块

因此它应该正常工作,但事实并非如此。任何帮助,将不胜感激。我对Ansible很新。

2 个答案:

答案 0 :(得分:2)

  

我在Ubuntu Vagrant机器上运行Ansible。

那么为什么首先使用yum而不是apt模块?

如果由于某种原因仍需要yum模块,请确保托管主机上安装了yum python软件包。

答案 1 :(得分:0)

使用包而不是yum模块,如剧本中的How to unify package installation tasks in ansible?所示。

当我阅读并阅读一本基于CentOS / RedHat编写的书时,我遇到了同样的错误。问题本身可以避免如下,但如果继续在Ubuntu上使用YUM,则会导致进一步的问题。

环境

DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"

确认症状

ansible@ip-172-31-38-30:~/playbook$ ansible-playbook sample.yaml -v
Using /etc/ansible/ansible.cfg as config file

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [ub01]

TASK [Ensure NTP (for time synchronization) is installed.] *********************
fatal: [ub01]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to ub01 closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_y0ULtJ/ansible_module_yum.py\", line 25, in <module>\r\n    import yum\r\nImportError: No module named yum\r\n", "msg": "MODULE FAILURE"}
        to retry, use: --limit @/home/ansible/playbook/sample.retry

PLAY RECAP *********************************************************************
ub01                       : ok=1    changed=0    unreachable=0    failed=1

安装yum

ansible@ip-172-31-38-30:~/playbook$ sudo apt install yum
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  yum
0 upgraded, 1 newly installed, 0 to remove and 58 not upgraded.
Need to get 486 kB of archives.
After this operation, 3,265 kB of additional disk space will be used.
Get:1 http://us-west-2.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 yum all 3.4.3-3 [486 kB]
Fetched 486 kB in 0s (12.3 MB/s)
Selecting previously unselected package yum.
(Reading database ... 110977 files and directories currently installed.)
Preparing to unpack .../archives/yum_3.4.3-3_all.deb ...
Unpacking yum (3.4.3-3) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up yum (3.4.3-3) ...

验证原始问题已消失

ansible@ip-172-31-38-30:~/playbook$ ansible-playbook sample.yaml -v
Using /etc/ansible/ansible.cfg as config file

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [ub01]

TASK [Ensure NTP (for time synchronization) is installed.] *********************
fatal: [ub01]: FAILED! => {"changed": false, "failed": true, "msg": "No package matching 'ntp' found available, installed or updated", "rc": 126, "results": ["No package matching 'ntp' found available, installed or updated"]}
        to retry, use: --limit @/home/ansible/playbook/sample.retry

PLAY RECAP *********************************************************************
ub01                       : ok=1    changed=0    unreachable=0    failed=1

相关问题

python的位置可能是Ansible和Yum的原因。

请注意/ usr / bin / yum是指/ usr / bin / python。

#! /usr/bin/python 
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was: