# aws\_ec2 & constructed not working as per documentation?

**URL:** <https://forum.ansible.com/t/aws-ec2-constructed-not-working-as-per-documentation/29993>\
**Category:** Ansible Project\
**Created:** [March 26, 2019, 6:40pm UTC](https://forum.ansible.com/t/aws-ec2-constructed-not-working-as-per-documentation/29993 "2019-03-26T18:40:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derek\_Murawsky](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Derek\_Murawsky](https://forum.ansible.com/u/Derek_Murawsky)\
**Post date:** [March 26, 2019, 6:40pm UTC](https://forum.ansible.com/t/aws-ec2-constructed-not-working-as-per-documentation/29993/1 "2019-03-26T18:40:26Z")

</div>

Hi All,

I’m trying to create a dynamic group of hosts that are in the intersection of 3 other groups. From what I am reading, I see that the new aws\_ec2 and constructed inventory plugins should be able to do what I want. However I try per the documentation and it doesn’t appear to be working.

I have the following:

aws\_ec2.yml

plugin: aws\_ec2  
regions:

- us-west-2

boto\_profile: correct\_profile  
hostnames:

- private-ip-address

1-groups.config

plugin: constructed  
keyed\_groups:

- prefix: tag  
key: tags
- prefix: instance\_type  
key: instance\_type
- key: ‘security\_groups|json\_query(“.group\_name”)’  
prefix: “security\_group”
- key: placement.region  
prefix: aws\_region
- key: platform  
prefix: platform  
groups:  
managed\_web\_servers: (group\_names|intersect([‘platform\_windows’,‘tag\_creator\_deployagent\_service’]))

# complex group membership

multi\_group: (group\_names)

I run it with

`  
ansible-inventory -i inventory/path/aws\_ec2.yml -i inventory/1-groups.config

`

In my output, I do see the platform\_windows and tag\_creator\_deployagent\_service groups. I do see multi\_group as well. However managed\_web\_servers are nowhere to be found. I thought I pulled this from the documentation correctly, but it’s not doing what I suspect it should. Could anyone share advice on this and/or help me debug it? There don’t seem to be a lot of examples of the new inventory plugins, or my google-fu is failing me.

Thanks,  
-Derek

---

<div class="post-metadata">

**Author:** ![Derek\_Murawsky](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Derek\_Murawsky](https://forum.ansible.com/u/Derek_Murawsky)\
**Post date:** [March 26, 2019, 6:57pm UTC](https://forum.ansible.com/t/aws-ec2-constructed-not-working-as-per-documentation/29993/2 "2019-03-26T18:57:21Z")

</div>

So after rereading the constructed documentation, and fiddling around, I managed to get this working.

RE: [constructed Documentation](https://docs.ansible.com/ansible/latest/plugins/inventory/constructed.html?highlight=constructed): “Only variables already available from previous inventories or the fact cache can be used for templating.” wasn’t quite clear. I assumed that variables and groups created within constructed would be available within constructed and that is not the case. By creating the source groups in the aws\_ec2.yml file, I was then able to create my dynamic logical groups in 1-groups.config. The results are below.

aws\_ec2.yml

plugin: aws\_ec2  
regions:

- us-west-2

boto\_profile: correct\_profile  
keyed\_groups:

- prefix: tag  
key: tags
- prefix: instance\_type  
key: instance\_type
- key: ‘security\_groups|json\_query(“.group\_name”)’  
prefix: “security\_group”
- key: placement.region  
prefix: aws\_region
- key: platform  
prefix: platform

hostnames:

- private-ip-address

1-groups.config

plugin: constructed  
groups:  
managed\_web\_servers: (group\_names|intersect([‘platform\_windows’,‘tag\_creator\_deployagent\_service’,‘tag\_Name\*web\_server’]))
