ansible return 代码 0 用于操作,但仍然没有剩余主机

ansible return code 0 for action but still getting NO MORE HOSTS LEFT

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'

当我是 运行 我的 plabook 时,即使 return status/code rc 它也会出错0 并且如果我打开调试 (-vvv),整个 ok:... 输出为绿色(而不是失败的红色step/action)。

问题:

  1. 为什么我会收到此 NO MORE HOSTS LEFT 错误,当 "rc": 0 并且本地主机的整个输出颜色为绿色.所有软件包都已安装。请参阅底部的输出。

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

所以,为了修复它,我还尝试了 运行 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 playbook,它再次出现同样的问题。

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   

似乎 Ansible 的 yum 模块不支持第二个项目符号 2。因此,我不得不使用 command 模块(我之前不喜欢使用它)因为这将解决错误。

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

或更好用,

- name: Yum complete transaction cleanup only
  command: yum-complete-transaction --cleanup-only
  become_user: root

仍然,问题 1 仍未得到解答,为什么当 rc = 0 / 输出为绿色时,ansible playbook 操作失败。