Ansible playbook 在所有 Ubuntu 服务器上都失败

bub*_*000 4 python ubuntu openssh ansible

我在 CentOS 服务器上运行 Ansible,并且可以在 Windows 和 RHEL/CentOS Linux 服务器上成功运行 playbook,但令我震惊的是我无法让 playbook 在任何 Ubuntu 服务器(v14.04、v16.04 或 v18.04)上运行- 包括 AWS 托管实例)!

奇怪的是Anible hostname -m ping 命令在所有 Ubuntu 主机上都可以正常工作......

我尝试将 CentOS 和 OpenSSH 更新到最新版本,但没有成功。我正试图解决这个问题,所以我希望有人能帮助我......

我的 Ansible 设置如下:

[root@ansible ansible]# ansible --version
ansible 2.9.3
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Run Code Online (Sandbox Code Playgroud)

CentOS版本:

[root@ansible ansible]# rpm -q centos-release
centos-release-7-7.1908.0.el7.centos.x86_64
Run Code Online (Sandbox Code Playgroud)

OpenSSH 版本:

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
Run Code Online (Sandbox Code Playgroud)

在详细模式下运行 playbook 会产生以下输出:

TASK [Installing package nginx] ***************************************************************************************************************************************
task path: /etc/ansible/sample.yml:7
<192.168.xxx.xxx> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.xxx.xxx> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/e8342f25c3 192.168.xxx.xxx '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<192.168.xxx.xxx> (0, '/root\n', '')
<192.168.xxx.xxx> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.xxx.xxx> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/e8342f25c3 192.168.xxx.xxx '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642 `" && echo ansible-tmp-1581462806.41-181529489855642="` echo /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642 `" ) && sleep 0'"'"''
<192.168.xxx.xxx> (0, 'ansible-tmp-1581462806.41-181529489855642=/root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642\n', '')
Using module file /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/apt.py
<192.168.xxx.xxx> PUT /root/.ansible/tmp/ansible-local-9871PVuptY/tmpt4YxAm TO /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642/AnsiballZ_apt.py
<192.168.xxx.xxx> SSH: EXEC sshpass -d8 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/e8342f25c3 '[192.168.xxx.xxx]'
<192.168.xxx.xxx> (0, 'sftp> put /root/.ansible/tmp/ansible-local-9871PVuptY/tmpt4YxAm /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642/AnsiballZ_apt.py\n', '')
<192.168.xxx.xxx> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.xxx.xxx> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/e8342f25c3 192.168.xxx.xxx '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642/ /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642/AnsiballZ_apt.py && sleep 0'"'"''
<192.168.xxx.xxx> (0, '', '')
<192.168.xxx.xxx> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.xxx.xxx> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/e8342f25c3 -tt 192.168.xxx.xxx '/bin/sh -c '"'"'/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642/AnsiballZ_apt.py && sleep 0'"'"''
<192.168.xxx.xxx> (1, '\r\n{"msg": "value of state must be one of: absent, build-dep, fixed, latest, present, got: installed", "failed": true, "invocation": {"module_args": {"state": "installed", "update_cache": true, "pkg": "nginx", "package": ["nginx"], "cache_valid_time": 0, "purge": false, "force": false, "dpkg_options": "force-confdef,force-confold", "autoremove": false, "autoclean": false, "only_upgrade": false, "force_apt_get": false, "allow_unauthenticated": false}}}\r\n', 'Shared connection to 192.168.xxx.xxx closed.\r\n')
<192.168.xxx.xxx> Failed to connect to the host via ssh: Shared connection to 192.168.xxx.xxx closed.
<192.168.xxx.xxx> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.xxx.xxx> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/e8342f25c3 192.168.xxx.xxx '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1581462806.41-181529489855642/ > /dev/null 2>&1 && sleep 0'"'"''
<192.168.xxx.xxx> (0, '', '')
fatal: [ubuntu_host]: FAILED! => {
Run Code Online (Sandbox Code Playgroud)

Vla*_*tka 5

“msg”:“状态值必须是以下之一:缺席、构建依赖、固定、最新、存在、已安装”,“失败”:true,“调用”:{“module_args”:{“state”: “已安装”,“update_cache”:true,“pkg”:“nginx”,“package”:[“nginx”],“cache_valid_time”:0,“purge”:false,“force”:false,“dpkg_options”: “force-confdef,force-confold”,“autoremove”:假,“autoclean”:假,“only_upgrade”:假,“force_apt_get”:假,“allow_unauthenticated”:假}

答:答案包含在错误消息中。详情请参阅apt 。