# Do YAML inventory plugins support inheritance?

**URL:** <https://forum.ansible.com/t/do-yaml-inventory-plugins-support-inheritance/28801>\
**Category:** Ansible Project\
**Created:** [October 16, 2018, 7:19pm UTC](https://forum.ansible.com/t/do-yaml-inventory-plugins-support-inheritance/28801 "2018-10-16T19:19:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Knights1](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@Guy\_Knights1](https://forum.ansible.com/u/Guy_Knights1)\
**Post date:** [October 16, 2018, 7:19pm UTC](https://forum.ansible.com/t/do-yaml-inventory-plugins-support-inheritance/28801/1 "2018-10-16T19:19:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rybrown1](https://avatars.discourse-cdn.com/v4/letter/r/49beb7/32.png) [@rybrown1](https://forum.ansible.com/u/rybrown1)\
**Post date:** [October 16, 2018, 8:46pm UTC](https://forum.ansible.com/t/do-yaml-inventory-plugins-support-inheritance/28801/2 "2018-10-16T20:46:24Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Guy\_Knights1](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@Guy\_Knights1](https://forum.ansible.com/u/Guy_Knights1)\
**Post date:** [October 20, 2018, 12:03am UTC](https://forum.ansible.com/t/do-yaml-inventory-plugins-support-inheritance/28801/3 "2018-10-20T00:03:26Z")

</div>

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