Ansible,连接到 AWS VPC 中的堡垒服务器,主机无法访问
Ansible, connecting to bastion server in AWS VPC, host unreachable
如何使用 Ansible 2.x 连接到 AWS VPC 中的堡垒服务器以执行 Docker 集群设置?我看过 this question and the 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 选项连接到我的 VPC 中的私有主机,例如:
ssh -J user@my.bastion.server.com user@vpc.host.private.ip
。
- 我正在使用 Ansible 的 ec2.py 动态清单,ec2.ini 配置为映射给定标签条目的私有 ips。
这是一个 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
瞧!
如何使用 Ansible 2.x 连接到 AWS VPC 中的堡垒服务器以执行 Docker 集群设置?我看过 this question and the 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 选项连接到我的 VPC 中的私有主机,例如:
ssh -J user@my.bastion.server.com user@vpc.host.private.ip
。 - 我正在使用 Ansible 的 ec2.py 动态清单,ec2.ini 配置为映射给定标签条目的私有 ips。
这是一个 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
瞧!