Ansible error: /bin/sh: -c: line 0: unexpected EOF while looking for matching "

Ansible error: /bin/sh: -c: line 0: unexpected EOF while looking for matching "

我正在尝试将 Ansible 与多个 CoreOS 虚拟机一起使用。我已经安装了 ActivePython,系统可以识别二进制文件。当我尝试使用内置的 Ansible 模块 (ping) 进行测试时,它会抛出以下错误:

deploy@kube-bh:~$ ansible dhcp-coreos155 -m ping
dhcp-coreos155 | FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Shared connection to dhcp-coreos155 closed.\r\n", 
    "module_stdout": "/bin/sh: -c: line 0: unexpected EOF while looking for matching `\"'\r\n/bin/sh: -c: line 1: syntax error: unexpected end of file\r\n", 
    "msg": "MODULE FAILURE", 
    "rc": 1
}

有趣的是,如果我 运行 使用 -m raw 的 Ansible 命令,它会成功:

deploy@kube-bh:~$ ansible dhcp-coreos155 -m raw -a 'uptime'
dhcp-coreos155 | SUCCESS | rc=0 >>
 20:02:21 up 1 day, 22:11,  2 users,  load average: 0.00, 0.00, 0.00
Shared connection to dhcp-coreos155 closed.

我在失败的命令上使用了 -vvvv 标志来查看连接状态,看起来 SSH 正在正确连接到 CoreOS 节点。我确实收集了更多信息,但错误发生的原因尚不清楚。

<dhcp-coreos155> ESTABLISH SSH CONNECTION FOR USER: deploy
<dhcp-coreos155> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="/home/deploy/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=deploy -o ConnectTimeout=10 -o ControlPath=/home/deploy/.ansible/cp/6852b73873 -tt dhcp-coreos155 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-fisdfsesqopuqybnmnfhfdijsvkmxvoh; /home/deploy/bin/python" /home/deploy/.ansible/tmp/ansible-tmp-1510602904.61-255211842882017/ping.py; rm -rf "/home/deploy/.ansible/tmp/ansible-tmp-1510602904.61-255211842882017/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''
<dhcp-coreos155> (1, '/bin/sh: -c: line 0: unexpected EOF while looking for matching `"\'\r\n/bin/sh: -c: line 1: syntax error: unexpected end of file\r\n', 'Shared connection to dhcp-coreos155 closed.\r\n')

对我来说,您似乎在某处弄乱了 Python 可执行文件定义(您没有显示配置,很可能是 Ansible 清单或 ansible.cfg)——有一个不平衡的引用在 Ansible 执行的命令中标记:

 /home/deploy/bin/python"

Shell 打开一个引号,但在找到匹配的右引号之前,整个命令结束,因此抛出一个意外的 EOF-found 异常。


raw模块没有调用Python,所以没有错误。