小编cup*_*kes的帖子

如何从 AWS 上的 ansible 动态清单返回私有 IP?

无论我尝试什么,出于某种原因,当我使用 ansible 动态清单脚本 (ec2.py+ec2.ini) 运行 ansible ad-hoc 模块时,只会返回用于标记查询的公共IP,并尝试通过 SSH 连接到目标的公共IP。例如,如果我运行:

ansible -m ping tag_env_dev
Run Code Online (Sandbox Code Playgroud)

然后,它尝试通过公共 IP 进行连接,尽管私有 IP 更可取(出于安全性、复杂性和成本原因)。我试图在我的 ec2.ini 文件中调整以下选项:

regions = us-east-1 # to restrict to us-east-1 region
destination_variable = public_dns_name # I've also tried private_dns_name and private_ip_address, all of which still attempt to connect to the public IP of the destination instance(s)
vpc_destination_variable = ip_address # also tried private_ip_address 
Run Code Online (Sandbox Code Playgroud)

如果我运行./ec2.py --list --refresh-cache | grep -B 5 -A 5 "tag_env_dev",我会得到一个只返回公共 IP 的结果: …

amazon-ec2 amazon-web-services ansible

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

amazon-ec2 ×1

amazon-web-services ×1

ansible ×1