![](/img/trans.png)
[英]Configuring multiple AWS Accounts for Ansible ec2 dynamic inventory
[英]Ansible AWS ec2 module with tags and dynamic inventory returns wrong hosts
我在同一帐户下有两个VPC,每个VPC都有几台具有专用IP的主机。
我有一台主机的标记为mobile
等于true
,另一台主机的标记为Environment
等于ci
,它们都具有相同的私有IP,但是它们位于不同的VPC中。
当我使用Ansible运行以下标签搜索时:
- name: "install security service"
hosts: "tag_Environment_{{ env }}:&tag_Service_{{ service }}_true"
使用参数env="ci"
和service="mobile"
,即使其中每个主机没有两个标签,我也可以返回其中一台主机。
由于它们具有相同的IP,因此搜索似乎正在合并结果,因此返回的主机只有一个标签。
是的, ec2.py
清单脚本使用vpc_destination_variable
参数来命名主机。
对于VPC,通常在ec2.ini中将其设置为private_ip_address
,因此清单中只能有一个具有相同IP的主机。
为了解决您的问题,您可以尝试在将主机保存到清单之前尝试用instance_filters
过滤主机。
来自ec2.ini的示例:
# Retrieve only instances with (key=value) env=staging tag
# instance_filters = tag:env=staging
# Retrieve only instances with role=webservers OR role=dbservers tag
# instance_filters = tag:role=webservers,tag:role=dbservers
# Retrieve only t1.micro instances OR instances with tag env=staging
# instance_filters = instance-type=t1.micro,tag:env=staging
# You can use wildcards in filter values also. Below will list instances which
# tag Name value matches webservers1*
# (ex. webservers15, webservers1a, webservers123 etc)
# instance_filters = tag:Name=webservers1*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.