Using loops with sub-elements/parameters ansible, particularly ec2 module

Hi,
Am trying to use Loop for ‘Volumes’ parameter of ec2 -

ec2:

prop1:

prop2:

volumes:

  • device_name : {{ item.key1 }}

  • volume_size: {{ item.key2 }}

with_items: {{ var}}

var:

{ ‘key1’ : ‘value1’ , ‘key2’ : ‘value2’}

{ ‘key1’ : ‘value3’ , ‘key2’ : ‘value4’}

I also did try with_dict but the loop does not correspond to the sub-element ‘volumes’, instead when it works without syntax errors, it creates multiple EC2 instances - each for one in the loop with the volume value.

Please advise how to use the ec2 module with loop for volumes, or if I have got looping sub-items incorrectly please hint on what am doing wrong.

Regards

The loop is for the whole task, that is why you get multiple instances. What you want is to pass the datastucture to the volumes key, jinja filters should help you with this.