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

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

问题描述

我正在使用 ansible 来自动化一些任务.其中之一要求我通过 ssh 连接到服务器 A,然后从 A 连接到 B,然后从 B 连接到 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?

推荐答案

鉴于您没有将 Paramiko 用于 ssh (transport = ssh),Ansible 将完全使用您的 ~/.ssh/config.因此,您可以在 ssh 配置中全局定义所有连接规则.

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

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