[英]Ansible AWS ec2 module with tags and dynamic inventory returns wrong hosts
I have two VPCs under the same account, each of which has several hosts with private IPs. 我在同一帐户下有两个VPC,每个VPC都有几台具有专用IP的主机。
I have one host with a tag mobile
equals to true
and another host with a tag of Environment
equals to ci
, both with the same private IP, but they reside in different VPCs. 我有一台主机的标记为
mobile
等于true
,另一台主机的标记为Environment
等于ci
,它们都具有相同的私有IP,但是它们位于不同的VPC中。
when I run the following tag search using Ansible: 当我使用Ansible运行以下标签搜索时:
- name: "install security service"
hosts: "tag_Environment_{{ env }}:&tag_Service_{{ service }}_true"
With the arguments env="ci"
and service="mobile"
I get one of the hosts back, even though each of the hosts doesn't have both tags. 使用参数
env="ci"
和service="mobile"
,即使其中每个主机没有两个标签,我也可以返回其中一台主机。
Since they have the same IP, it seems like the search is merging the results and thus returns a host which has only one of the tags. 由于它们具有相同的IP,因此搜索似乎正在合并结果,因此返回的主机只有一个标签。
Yes, ec2.py
inventory script uses vpc_destination_variable
parameter to name hosts. 是的,
ec2.py
清单脚本使用vpc_destination_variable
参数来命名主机。
For VPC it is usually set to private_ip_address
in ec2.ini , so you can have only one host with same IP in your inventory. 对于VPC,通常在ec2.ini中将其设置为
private_ip_address
,因此清单中只能有一个具有相同IP的主机。
To overcome your situation, you may try play with instance_filters
to filter hosts before they are saved to inventory. 为了解决您的问题,您可以尝试在将主机保存到清单之前尝试用
instance_filters
过滤主机。
example from ec2.ini: 来自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.