[英]Ansible aws_ec2 plugin set ansible_host: from multiple private ips based on 'description:'
[英]Ansible: ec2 aws plugin - How to associate ec2 host to ansible group based on aws_profile?
我確定必須有一個簡單的答案,但是,當我使用aws_ec2
插件為 Ansible 創建動態清單時,我使用以下設置以便我可以將配置文件傳遞到清單中(以獲取正確的憑據) :
plugin: aws_ec2
aws_profile: "{{ lookup('env', 'AWS_PROFILE') | default('dev-profile', true) }}"
regions:
- us-east-1
現在,我希望所有這些主機都與一個組相關聯,該組具有傳入的 AWS_PROFILE 的名稱。我該怎么做?
我試過了:
groups:
dev_group: aws_profile == 'dev-profile'
test_group: aws_profile == 'test-profile'
但沒有成功(沒有創建組)。
事實上,您在清單中為參數aws_profile
設置了一個值並不能使其在變量中可用。
所以你要做的是在你的groups
條件中重復使用相同的查找:
groups:
dev_group: lookup('env', 'AWS_PROFILE') | default('dev-profile', true) == 'dev-profile'
test_group: lookup('env', 'AWS_PROFILE') | default('dev-profile', true) == 'test-profile'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.