使用Ansible SSH到远程服务器 [英] SSH to remote server using ansible

查看:129
本文介绍了使用Ansible SSH到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ansible来自动化一些任务.其中之一要求我先将服务器SSH到服务器A,然后再从A SSH到B,然后再从B SSH到C.我似乎找不到任何方法来做到这一点.有什么建议吗?

I'm using ansible to automate some tasks. One of those requires me to ssh to server A, then to B from A and then to C from B. I can't seem to find any way to get ansible to do that. Any suggestions?

推荐答案

鉴于您没有对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
  • 这篇关于使用Ansible SSH到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆