托管节点上是否需要 SSH SFTP 子系统才能使 Ansible 工作?

bra*_*rry 7 linux ssh sftp ansible

当我运行时:

ansible all -a "/bin/echo hello" -u myuser
Run Code Online (Sandbox Code Playgroud)

我回来了:

mydomain.myhost.com | FAILED => failed to open a SFTP connection (Channel closed.)
Run Code Online (Sandbox Code Playgroud)

SFTP 子系统在我尝试连接的受管节点上被禁用。

受管节点上是否需要 SFTP?Ansible 文档没有特别提到 SFTP:http ://docs.ansible.com/intro_installation.html#managed-node-requirements

我尝试在 ansible.cfg 中设置这个值

scp_if_ssh=True
Run Code Online (Sandbox Code Playgroud)

……但是没有效果。(感谢神奇的神奇狗弗雷德的建议。)

我还确保我的非交互式 shell 不会产生这里建议的任何输出。

Fre*_*Dog 5

是的,ansible 取决于能够将文件传输到远程机器。默认情况下,它使用 sftp 来执行此操作。您可以覆盖它以使用 scp 使用

scp_if_ssh
Occasionally users may be managing a remote system that doesn’t have SFTP enabled. If set to True, we can cause scp to be used to transfer remote files instead:

scp_if_ssh=False
There’s really no reason to change this unless problems are encountered, and then there’s also no real drawback to managing the switch. Most environments support SFTP by default and this doesn’t usually need to be changed.
Run Code Online (Sandbox Code Playgroud)

以上信息取自本页:

http://docs.ansible.com/intro_configuration.html#openssh-specific-settings


bra*_*rry 5

这就是我最终所做的:

  1. 复制/etc/ansible/ansible.cfg~/.ansible.cfg
  2. 已编辑 ~/.ansible.cfg
  3. 变成#scp_if_ssh = Falsescp_if_ssh = True
  4. 添加ssh_args =[ssh_connection]部分。
  5. -c SSH带标志运行我的命令

感谢神奇狗 Fred为我指明了正确的方向。

  • 最好为您的设置提供代码段(`ansible.cfg`),我注意到`scp_if_ssh=True`应放在`[ssh_connection]`下面,`ssh_args`是可选的,取决于每个配置。 (3认同)