gpt4 book ai didi

ssh - 与服务器的共享连接已关闭

转载 作者:行者123 更新时间:2023-12-02 14:13:48 30 4
gpt4 key购买 nike

当我运行这个:

$ ansible -i s1, s1 -m raw -a 'echo test' -u root -k

我得到:
s1 | SUCCESS | rc=0 >>
test
Shared connection to s1 closed.

但是这样:
$ ansible -i s1, s1 -m command -a 'echo test' -u root -k

我没有收到“与s1的共享连接已关闭”的信息。部分:
s1 | SUCCESS | rc=0 >>
test

这是为什么?

附言以上是重现该问题的简化方法。我面临的是,在运行剧本时,我得到了这条多余的线。

UPD 该行显然来自 ssh。如果我使用 raw运行 -vvvv命令,我将得到:
Using /etc/ansible/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
<s1> ESTABLISH SSH CONNECTION FOR USER: root
<s1> SSH: EXEC sshpass -d13 ssh -vvv -C -o ControlMaster=auto
-o ControlPersist=60s -o User=root -o ConnectTimeout=10
-o ControlPath=/home/yuri/.ansible/cp/ansible-ssh-%h-%p-%r -tt s1
'echo test'
s1 | SUCCESS | rc=0 >>
test
OpenSSH_7.4p1, OpenSSL 1.0.2k 26 Jan 2017
debug1: Reading configuration data /home/yuri/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: auto-mux: Trying existing master
debug1: Control socket "/home/yuri/.ansible/cp/ansible-ssh-s1-22-root" does not exist
<...a lot of output from ssh...>

但是有了 command,它就是:
Using /etc/ansible/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from
/usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
Using module file
/usr/lib/python2.7/site-packages/ansible/modules/core/commands/command.py
<s1> ESTABLISH SSH CONNECTION FOR USER: root
<s1> SSH: EXEC sshpass -d13 ssh -vvv -C -o ControlMaster=auto
-o ControlPersist=60s -o User=root -o ConnectTimeout=10
-o ControlPath=/home/yuri/.ansible/cp/ansible-ssh-%h-%p-%r s1
'/bin/sh -c '"'"'(
umask 77
&& mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1488989540.6-73006073289737 `"
&& echo ansible-tmp-1488989540.6-73006073289737="` echo ~/.ansible/tmp/ansible-tmp-1488989540.6-73006073289737 `"
) && sleep 0'"'"''
<s1> PUT /tmp/tmpes82wL TO
/root/.ansible/tmp/ansible-tmp-1488989540.6-73006073289737/command.py
<s1> SSH: EXEC sshpass -d13 sftp -o BatchMode=no -b - -vvv -C
-o ControlMaster=auto -o ControlPersist=60s -o User=root
-o ConnectTimeout=10
-o ControlPath=/home/yuri/.ansible/cp/ansible-ssh-%h-%p-%r '[s1]'
<s1> ESTABLISH SSH CONNECTION FOR USER: root
<s1> SSH: EXEC sshpass -d13 ssh -vvv -C -o ControlMaster=auto
-o ControlPersist=60s -o User=root -o ConnectTimeout=10
-o ControlPath=/home/yuri/.ansible/cp/ansible-ssh-%h-%p-%r s1
'/bin/sh -c '"'"'
chmod u+x /root/.ansible/tmp/ansible-tmp-1488989540.6-73006073289737/ /root/.ansible/tmp/ansible-tmp-1488989540.6-73006073289737/command.py
&& sleep 0'"'"''
<s1> ESTABLISH SSH CONNECTION FOR USER: root
<s1> SSH: EXEC sshpass -d13 ssh -vvv -C -o ControlMaster=auto
-o ControlPersist=60s -o User=root -o ConnectTimeout=10
-o ControlPath=/home/yuri/.ansible/cp/ansible-ssh-%h-%p-%r -tt s1
'/bin/sh -c '"'"'
/usr/bin/python /root/.ansible/tmp/ansible-tmp-1488989540.6-73006073289737/command.py;
rm -rf "/root/.ansible/tmp/ansible-tmp-1488989540.6-73006073289737/" > /dev/null 2>&1
&& sleep 0'"'"''
s1 | SUCCESS | rc=0 >>
test

所有 ssh输出到哪里去了?

最佳答案

Shared connection to s1 closed.



此消息是来自ssh客户端的错误消息。

使用 raw: echo test,Ansible执行 ssh <many parameters> s1 'echo test',您将从 ssh 命令获得stdout / stderr。这样,有关共享连接的消息就会在您的任务结果中弹出。

使用 command: echo test Ansible复制python-wrapper( command.py)并执行此包装器,这反过来产生 echo test并从 echo 命令捕获stdout / stderr。然后 command.pyecho / stdout / stderr键将 rc的结果打印为JSON对象。 ssh错误消息仍然会发生,但是您看不到它(它被Ansible过滤),因为Ansible get任务的结果来自JSON对象键,而不是ssh plain stdout / stderr / rc。

Where is all ssh output gone?



这是由于在处理原始/命令方面的相同差异。要查看详细的ssh输出,请设置 ANSIBLE_DEBUG=1环境变量。

如果要隐藏此错误消息,可以使用 ansible_ssh_extra_args='-o LogLevel=QUIET'库存变量。但是我不确定这是否还会带来其他意外结果。

关于ssh - 与服务器的共享连接已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42676161/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com