Thanks Ryan, I did some tests and got this working using the constructed
plugin.

One issue I ran into though is that the inventory plugin files appear to be
loaded alphabetically, so if the constructed inventory filename is
alphabetically 'smaller', the constructed inventory file will be loaded
first, and the host inventory may not yet be populated by the other
inventory files. I found an issue logged about this:
https://github.com/ansible/ansible/issues/31405. I've got around this in
the meantime by prefixing the name of my inventory file with 'z_'. It seems
to me that Ansible's behaviour should be to always load constructed
inventory files last since they rely purely on the output of other
inventory plugins.

Anyway, just noting that extra bit of info here in case anyone stumbles
upon this thread. Thanks again for your help!

Kind regards,
Guy

On Fri, 19 Oct 2018 at 15:39, Ryan Brown <[email protected]> wrote:

> Guy,
>
> It looks like the specific case you have of filtering based on a given tag
> can be solved without having several inventories.
>
> If you use the `constructed` part of inventory plugins,
> https://docs.ansible.com/ansible/2.7/plugins/inventory/constructed.html
> which lets you do all kinds of advanced grouping based on properties such
> as tags.
>
> Also, here's an issue you can watch which is related to allowing importing
> w/ vars. It doesn't extend to config, but would be the same principal.
>
> On Tuesday, October 16, 2018 at 3:19:31 PM UTC-4, Guy Knights wrote:
>>
>> I'm experimenting with the new AWS_EC2 plugin and have been wondering if
>> there's a way to streamline the file as we have separate inventory folders
>> for dev, demo and prod. Is there a way to do something like and 'include'
>> for the bulk of the YAML file content and just have the different
>> environment filters in each inventory's specific file? eg. something like
>> this:
>>
>> Central file (central.aws_ec2.yml):
>> plugin: aws_ec2
>> regions:
>>   - us-east-1
>>   - us-east-1
>>   - us-west-1
>>   - us-west-2
>>   - ap-southeast-2
>> filters:
>>   instance-state-name: running
>> strict_permissions: False
>> hostnames:
>>   - tag:Name
>>   - private-ip-address
>> strict: False
>> keyed_groups:
>>   - prefix: ''
>>     separator: ''
>>     key: tags.Type
>>
>> Demo inventory file (demo.aws_ec2.yml):
>> include: central.aws_ec2.yml
>> filters:
>>   tag:Environment: demo
>>
>> Thanks,
>> 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/Yu5yWu47zO0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5be0ede7-229b-4af5-9fb9-01810fe25511%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/5be0ede7-229b-4af5-9fb9-01810fe25511%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
<http://www.bluebatgames.com>
Guy Knights • Senior Systems Engineer
c: 778-996-2687p: 778-379-5120
<https://www.facebook.com/BlueBatGames/>
<https://www.linkedin.com/company/bluebat-games>
<https://twitter.com/BlueBatGames>  <http://www.bluebatgames.com>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFtmDk-H_BtXxBE8fFujpPhbzb87bLcoVAfE-uUHTEaNAYSVsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to