首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有标签和动态库存的Ansible AWS ec2模块返回错误的主机

带有标签和动态库存的Ansible AWS ec2模块返回错误的主机
EN

Stack Overflow用户
提问于 2017-07-23 23:38:47
回答 1查看 673关注 0票数 0

我在同一个账号下有两个私有网络,每个私有网络都有多个具有内网IP的宿主机。

我有一台主机的标签mobile等于true,另一台主机的标签Environment等于ci,这两台主机都有相同的内网IP,但它们驻留在不同的VPC中。

当我使用Ansible运行以下标签搜索时:

代码语言:javascript
复制
- name: "install security service"
  hosts: "tag_Environment_{{ env }}:&tag_Service_{{ service }}_true"

使用参数env="ci"service="mobile",我得到了其中一个主机,即使每个主机都没有这两个标签。

由于它们具有相同的IP,因此搜索似乎正在合并结果,从而返回一个只有一个标签的主机。

EN

回答 1

Stack Overflow用户

发布于 2017-07-24 18:24:01

是的,ec2.py inventory脚本使用vpc_destination_variable参数命名主机。

对于VPC,在ec2.ini中通常设置为private_ip_address,因此您的清单中只能有一台具有相同IP的主机。

要克服这种情况,您可以尝试使用instance_filters在将主机保存到清单之前对其进行过滤。

来自ec2.ini的示例:

代码语言:javascript
复制
# 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*
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45266894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档