aws_ec2 & constructed not working as per documentation?

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

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

RE: constructed Documentation: “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’]))