![](/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.