ansible返回代码0的行动,但仍然没有更多的主人左

时间:2016-12-29 22:37:54

标签: pip ansible ansible-playbook yum ansible-2.x

ansible 2.1.2.0

- name: Ensure/Install pre-requisite packages (RedHat)
  yum:
    name: "{{ item }}"
    state: installed
    update_cache: yes
  with_items:
    - 'pygpgme'
    - 'yum-utils'
    - 'python-pip'
    - 'facter'

当我正在运行我的电子书时,即使返回状态/代码 rc 0 并且如果我打开调试(-vvv),它也会出错整个 ok:... 输出为绿色(而不是红色,表示失败的步骤/动作)。

问题:

  1. 为什么我在“rc”:0 时出现此NO MORE HOSTS LEFT错误,并且整个输出颜色为绿色表示为localhost。所有软件包都已安装。见底部的输出。

  2. 如何在Ansible中执行此操作(如果可能,不使用command / shell模块)sudo yum-complete-transaction --cleanup-only,可通过yum模块执行此操作(如果可能)我在剧本中采取的同样yum行动?

  3. 所以,要修复它,我还尝试运行yum在命令行安装packages / pending(并且它显示无所事事,因为一切都是最新的):

    $ sudo yum install yum-utils pygpgme python-pip facter
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: centos.mirrors.hoobly.com
     * epel: mirrors.cat.pdx.edu
     * extras: mirror.spro.net
     * updates: mirror.tocici.com
    Package yum-utils-1.1.31-40.el7.noarch already installed and latest version
    Package pygpgme-0.3-9.el7.x86_64 already installed and latest version
    Package python2-pip-8.1.2-5.el7.noarch already installed and latest version
    Package facter-2.4.1-1.el7.x86_64 already installed and latest version
    Nothing to do
    

    重新播放了ansible剧本,并再次出现同样的错误。

    TASK [company.company-ansible : Ensure/Install pre-requisite packages (RedHat)] ***
    task path: /home/vagrant/aks/ansible/tasks/yum_install.yml:3
    <localhost> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
    <localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1483049236.46-121920804274438 `" && echo ansible-tmp-1483049236.46-121920804274438="` echo $HOME/.ansible/tmp/ansible-tmp-1483049236.46-121920804274438 `" ) && sleep 0'
    <localhost> PUT /tmp/tmpxzRchU TO /home/vagrant/.ansible/tmp/ansible-tmp-1483049236.46-121920804274438/yum
    <localhost> EXEC /bin/sh -c 'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1483049236.46-121920804274438/ /home/vagrant/.ansible/tmp/ansible-tmp-1483049236.46-121920804274438/yum && sleep 0'
    <localhost> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-bteisecjvsnsqhbbsohdrpswvjynpydi; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1483049236.46-121920804274438/yum; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1483049236.46-121920804274438/" > /dev/null 2>&1'"'"' && sleep 0'
    ok: [localhost] => (item=[u'pygpgme', u'yum-utils', u'python-pip', u'facter']) => {"changed": false, "failed": true, "invocation": {"module_args": {"conf_file": null, "disable_gpg_check": false, "disablerepo": null, "enablerepo": null, "exclude": null, "install_repoquery": true, "list": null, "name": ["pygpgme", "yum-utils", "python-pip", "facter"], "state": "installed", "update_cache": true, "validate_certs": true}, "module_name": "yum"}, "item": ["pygpgme", "yum-utils", "python-pip", "facter"], "msg": "The following packages have pending transactions: python2-pip-noarch", "rc": 0, "results": ["pygpgme-0.3-9.el7.x86_64 providing pygpgme is already installed", "yum-utils-1.1.31-40.el7.noarch providing yum-utils is already installed"]}
    
    NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @/home/vagrant/aks/ansible/company-ansible.retry
    
    PLAY RECAP *********************************************************************
    localhost                  : ok=1    changed=0    unreachable=0    failed=1   
    

1 个答案:

答案 0 :(得分:0)

似乎Ansible的__CDT_PARSER__模块不支持第二个子弹2.所以,我不得不使用yum模块(我不想更早地使用它)因为这将解决错误

command

或更好地使用,

- name: Yum complete transaction cleanup only
  command: sudo yum-complete-transaction --cleanup-only

尽管如此,问题1仍然没有回答为什么当- name: Yum complete transaction cleanup only command: yum-complete-transaction --cleanup-only become_user: root /输出为绿色时,然后ansible playbook操作失败。