且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Ansible SSH到远程服务器

更新时间:2023-02-02 17:45:42

鉴于您没有对ssh使用Paramiko(

Given that you do not use Paramiko for ssh (transport = ssh), Ansible will fully use your ~/.ssh/config. Therefore you can globally define all connection rules in your ssh configuration.

如果出于某种原因您希望Ansible不使用默认的ssh配置,而是提供单独的配置,则可以在ansible.cfg中定义:

If for some reason you want Ansible to not use your default ssh config but provide an separate configuration, you can define this in your ansible.cfg:

[ssh_connection]
ssh_args= -F "/path/to/ssh/config/specifically/for/ansible"

然后在您的ssh配置中设置连接规则.坚持您的示例:

In your ssh config then set up the connection rules. To stick with your example:

Host HostA
  HostName real-host-name-A.com

Host HostB
  HostName real-host-name-B.com
  ProxyCommand ssh -q HostA nc %h %p

Host HostC
  HostName real-host-name-C.com
  ProxyCommand ssh -q HostB nc %h %p

  • 与A的连接是直接的
  • 与B的连接通过A
  • 与C的连接通过B,而B通过A