如何使用 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",
大概值得一提的是:
ssh -J [email protected] [email protected]
.这是一个 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
瞧!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句