首页 文章

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

提问于
浏览
1

我正在尝试在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 fatal的模块:[localhost]:FAILED! => {“已更改”: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

    我在Ubuntu Vagrant机器上运行Ansible .

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

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

  • 2

    使用包而不是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:
    

相关问题