Constructing a List.

Hi,

Using a ‘shell’ task I’m obtaining a list of subnet id’s from Amazon, these subnet id’s I want to pass in to the ec2_elb_lb task.
However this task accepts a list for Subnets only, so is there a way to dynamically construct a list out of the id’s that I obtained?

Thanks,
Nico

Hi,

Instead of using shell, you could use a lookup plugin that will query the ids by name for you.
So when creating the subnets, give them a name and also store them in a list, e.g.
mysubnets:

  • subnet1
  • subnet2

You can then define your ELB like this:

ec2_elb_lb:

subnets: “{{ lookup(‘aws_subnet_ids_from_names’, (region, mysubnets)) }}”

Where region is a variable containing a region name, i.e. ‘eu-west-1’.
This will return a list of the subnet ids that the ec2_elb_lb module expects.
To use this, just copy the lookup plugin from here into a directory called lookup_plugins in the root of your project.

Jon

Hi Jon,

That is awesome. Thank you for sharing.

-- Best, Igor