Is there any way to specify a suffix for the keyed_groups option in the aws_ec2 inventory plugin? I’m looking at migrating from Ansible 2.4 to 2.6 and would like to switch from the old ec2 dynamic inventory script. However, we currently specify our host groups as “_servers”, eg. “web_servers”. Is there any way I can replicate this host group format in the aws_ec2 plugin or am I out of luck?
I know I could change the format of our host groups but I’d prefer not to have to do that if possible as there are conditional includes, etc I’d have to adjust as well.
Thanks,
Guy
Sure, just include the suffix in the key.
`
keyed_groups:
- prefix: ‘’
separator: ‘’
key: tags.Class ~ ‘_servers’
`
`
“all”: {
“children”: [
“aws_ec2”,
“builder_servers”,
“ctools_mx_servers”,
“dev_servers”,
“dnsbl_servers”,
“egress_servers”,
“jail_servers”,
“master_servers”,
“mx_servers”,
“relay_egress_servers”,
“syslog_servers”,
“ungrouped”
]
`
Great, thanks! That seems to have worked.
One other question related to aws_ec2 - I usually pass the AWS_PROFILE var on the command line when I call ansible, eg. “AWS_PROFILE=myawsprofile ./ansible-playbook -i inventory/prod/ playbooks/site.yml”. However, with my aws_ec2 inventory file, if I leave out the boto_profile and regions variables the inventory list returns nothing. I have to explicitly include these two parameters with a specific profile name and region in order for it to return a list of my instances. I tried setting boto_profile: ‘env:AWS_PROFILE’ or just ‘AWS_PROFILE’ (in addition to just leaving it out) but it doesn’t work. What am I doing wrong?
Thanks again,
Guy
Never mind, I worked out that if I include the region (but not the boto_profile parameter) then it works. Not sure why it’s not using the profile region defined in ~/.aws/config but it’s not a big deal.