如何使用Ansible 2.x连接到AWS VPC中的堡垒服务器以执行Docker群设置?我见过this question和official FAQ。
已经尝试通过--extra-vars
提供以下内容:
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q user@my.bastion.server.com"'
,或者甚至将ansible.cfg
与上面的参数一起使用,甚至类似:
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=600s -J ec2-
user@my.bastion.dns.com
我尝试了很多组合,但是我总是在运行手册中收到在运行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",
可能值得一提:
ssh -J user@my.bastion.server.com user@vpc.host.private.ip
。 答案 0 :(得分:1)
这是一个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
瞧!