Well, after some more painful trial and error, and pissing Amazon off for 
sure, here's a working solution: 

I hope this saves someone some pain in the future. 

 - name: data volumes
         ec2_vol: 
         aws_access_key: "{{ key }}" 
         aws_secret_key: "{{ secret }}" 
         instance: "{{ item.instances.0.id }}" 
         region: "{{item.instances.0.region}}" 
         name: "{{ item.instances.0.tags.Name }}_data" 
         volume_size: {{data_vol_size}} 
         volume_type: gp2 
         device_name: /dev/xvdb 
         with_items: ec2.results 
         register: ec2_vol





On Friday, March 11, 2016 at 9:46:25 AM UTC-5, [email protected] wrote:
>
> Hi, 
>
> I am having issues with passing ec2 instance provisioning results to other 
> tasks in a playbook. 
>
> I can launch instances, and then use "
> register: ec2
>
> " to register a dictionary of the results. But I cannot seem to extract 
> the instance id later. 
>
> Using debug I can see i get valid results: 
>
>
> TASK [debug] 
> *******************************************************************
>
>  
>
> ok: [localhost] => { 
>
>     "ec2.results": [ 
>
>         { 
>
>             "_ansible_no_log": false,  
>
>             "changed": true,  
>
>             "instance_ids": [ 
>
>                 "i-5bbc7cee" 
>
>             ],  
>
>             "instances": [ 
>
>                 { 
>
>                     "ami_launch_index": "0",  
>
>                     "architecture": "x86_64",  
>
>                     "block_device_mapping": { 
>
>                         "/dev/xvda": { 
>
>                             "delete_on_termination": true,  
>
>                             "status": "attached",  
>
>                             "volume_id": "vol-352da188" 
>
>                         } 
>
>                     },  
>
>                     "dns_name": "",  
>
>                     "ebs_optimized": false,  
>
>                     "groups": { 
>
>                         "sg-2b37d84f": "mongo" 
>
>                     },  
>
>                     "hypervisor": "xen",  
>
>                     "id": "i-5bbc7cee",  
>
>                     "image_id": "ami-d1f482b1",  
>
>                     "instance_type": "t2.micro",  
>
>                     "kernel": null,  
>
>                     "key_name": "keypair",  
>
>                     "launch_time": "2016-03-11T13:33:09.000Z",  
>
>                     "placement": "us-west-1c",  
>
>                     "private_dns_name": 
> "ip-172-x-x-x.us-west-1.compute.internal",  
>
>                     "private_ip": "x.x.x.x",  
>
>                     "public_dns_name": "",  
>
>                     "public_ip": null,  
>
>                     "ramdisk": null,  
>
>                     "region": "us-west-1",  
>
>                     "root_device_name": "/dev/xvda",  
>
>                     "root_device_type": "ebs",  
>
>                     "state": "running",  
>
>                     "state_code": 16,  
>
>                     "tags": { 
>
>                         "Name": "mongo",  
>                     },  
>
>                     "tenancy": "default",  
>
>                     "virtualization_type": "hvm" 
>
>                 } 
>
>             ],  
>
>             "invocation": { 
>
>                 "module_args": { 
>
>                     "assign_public_ip": false,  
>
>                     "aws_access_key": "xxxxxxxxxxxxxxxxxxxxxx",  
>
>                     "aws_secret_key": 
> "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",  
>
>                     "count": 1,  
>
>                     "count_tag": { 
>
>                         "volumes": "data" 
>
>                     },  
>
>                     "ebs_optimized": false,  
>
>                     "ec2_url": null,  
>
>                     "exact_count": null,  
>
>                     "group": [ 
>
>                         "mongo" 
>
>                     ],  
>
>                     "group_id": null,  
>
>                     "id": null,  
>
>                     "image": "ami-d1f482b1",  
>
>                     "instance_ids": null,  
>
>                     "instance_profile_name": null,  
>
>                     "instance_tags": { 
>
>                         "Name": "mongo",  
>
>                     },  
>
>                     "instance_type": "t2.micro",  
>
>                     "kernel": null,  
>
>                     "key_name": "keypair",  
>
>                     "monitoring": false,  
>
>                     "network_interfaces": null,  
>
>                     "placement_group": null,  
>
>                     "private_ip": null,  
>
>                     "profile": null,  
>
>                     "ramdisk": null,  
>
>                     "region": "us-west-1",  
>
>                     "security_token": null,  
>
>                     "source_dest_check": true,  
>
>                     "spot_price": null,  
>
>                     "spot_type": "one-time",  
>
>                     "spot_wait_timeout": 600,  
>
>                     "state": "present",  
>
>                     "tenancy": "default",  
>
>                     "termination_protection": false,  
>
>                     "user_data": null,  
>
>                     "validate_certs": true,  
>
>                     "volumes": null,  
>
>                     "vpc_subnet_id": "subnet-703aa229",  
>
>                     "wait": true,  
>
>                     "wait_timeout": 300,  
>
>                     "zone": null 
>
>                 },  
>
>                 "module_name": "ec2" 
>
>             },  
>
>             "item": "mongo",  
>
>             
>
> ...

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/35aeb1ff-72ed-4204-9814-f94b631fcb96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to