Ansible,连接到 AWS VPC 中的堡垒服务器,主机无法访问

罗杰里奥·佩肖托

如何使用 Ansible 2.x 连接到 AWS VPC 中的堡垒服务器以执行 Docker 群设置?我见过这个问题官方常见问题解答

已经尝试通过--extra-vars:提供以下内容,ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q [email protected]"'甚至ansible.cfg与上面的参数一起使用,甚至类似:

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=600s -J ec2- 
[email protected]

我尝试了很多组合,但我总是在剧本中运行 ping 命令时收到此错误消息:

UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the 
host via ssh: ssh: connect to host 10.1.xx.xx port 22: Operation timed 
out\r\n",

大概值得一提的是:

  1. 我通常可以使用ssh -J选项连接到 VPC 中的私有主机,例如:ssh -J [email protected] [email protected].
  2. 我正在使用 Ansible 的 ec2.py 动态清单,其中 ec2.ini 配置为映射给定标签条目的私有 ip。
罗杰里奥·佩肖托

这是一个 ssh 配置错误问题。

我能够使用这些参数修复配置。

1) Ansible.cfg 文件

[ssh_connection]
ssh_args = -o ProxyCommand="ssh -W %h:%p -q $BASTION_USER@$BASTION_HOST" -o ControlPersist=600s 
control_path=%(directory)s/%%h-%%r
pipelining = True

2)ec2.ini文件

[ec2]
regions = us-xxxx-x
destination_variable = private_ip_address
vpc_destination_variable = private_ip_address

3)剧本执行命令

export BASTION_USER=xxx-xxxx;
export BASTION_HOST=ec2-xx-xx-xx-xx.xxxxx.compute.amazonaws.com;
ansible-playbook -u ec2-xxxx \
 -i ./inventory/ec2.py \
 ./playbook/ping.yml \
 --extra-vars \
 "var_hosts=tag_Name_test_private ansible_ssh_private_key_file=~/.ssh/my-test-key.pem" -vvv

瞧!

ping 成功

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章