AWS_EC2 plugin keyed_groups suffix option

294 views
Skip to first unread message

Guy Knights

unread,
Oct 15, 2018, 7:45:15 PM10/15/18
to Ansible Project
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 "<server type>_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

flowerysong

unread,
Oct 15, 2018, 8:07:06 PM10/15/18
to Ansible Project
On Monday, October 15, 2018 at 7:45:15 PM UTC-4, Guy Knights wrote:
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 "<server type>_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.

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"
        ]

Guy Knights

unread,
Oct 15, 2018, 8:28:52 PM10/15/18
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Zp2FtD1hiqQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2bb67f08-245e-41df-95d2-de695b47914b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Guy Knights • Senior Systems Engineer
c: 778-996-2687p: 778-379-5120
   

Guy Knights

unread,
Oct 16, 2018, 12:54:22 PM10/16/18
to Ansible Project
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.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages