vagrant上的Ansible错误中没有模块名Yum

vagrant上的Ansible错误中没有模块名Yum,vagrant,ansible,yum,Vagrant,Ansible,Yum,我在Ubuntu流浪者机器上用Ansible剧本做了一些实验。我编写了一个名为exampleyum.yml的简单剧本,如下所示: --- - hosts: local tasks: - name: Installing packages yum: name=httpd state=latest sudo: yes 当我跑的时候 ansible-playbook -i ~/inventory.ini exampleyum.yml 我得到以下错误: 任务执行

我在Ubuntu流浪者机器上用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,“失败”:true, “模块”\u stderr:“回溯(最近一次调用):\n文件” \“/tmp/ansible\u qeXrGO/ansible\u module\u yum.py\”,第25行,在\n中 导入yum\n导入错误:没有名为yum\n的模块,“模块\u stdout”:“”, “msg”:“模块故障”}

它给出了一些导入错误和模块故障。我在某处读到
Yum
是一个核心模块

因此它应该能正常工作,但它不能。任何帮助都将不胜感激。我对Ansible很陌生

我在Ubuntu流浪者机器上运行Ansible

那么,首先为什么要使用
yum
而不是
apt
模块呢


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

使用软件包,而不是手册中回答的yum模块

当我阅读并遵循一本基于CentOS/RedHat编写的书时,我也犯了同样的错误。这个问题本身可以避免,如下所示,但如果继续在Ubuntu上使用YUM,将导致进一步的问题

环境 症状确认 确认原始问题已消失 相关问题 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:

谢谢,但我想使用的是Yum模块,而不是apt模块。我已经安装了yum-python包,但它似乎仍然不起作用。Yum是RedHat系列发行版的软件包管理器。Apt是Debian系列发行版的软件包管理器。Ubuntu是Debian家族发行版。你应该在Ubuntu上使用apt。你需要提供一个令人信服的理由来解释为什么你不能这样做。谢谢,@XiongChiamiov。我在试着用yum。我太天真了。我没有寻找像“apt”或“package”这样的其他选项。他们现在工作得很好。目前,我无法提出更多问题。请您投票支持我的问题好吗?您可以在Ansible:中使用“package”命令而不是apt/yum,它将检测您已经安装了什么软件包管理器(在ubuntu上尝试使用yum没有多大意义)。我不知道“package”命令。谢谢@BrunoB.Carvalh让我知道。这很有帮助。目前,我无法提出更多问题。你能把我的问题投赞成票吗?
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
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
#! /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: