Extracting data from ec2 output

hello all,

After executing ec2 create, with “with_sequence”, i need to retrieve each instance’s “id”, “dns_name” and “tags”->“Name”.

the response is as follows:

`
<127.0.0.1> EXEC /bin/sh -c ‘rm -f -r /home/admin/.ansible/tmp/ansible-tmp-1525715943.61-189658929132615/ > /dev/null 2>&1 && sleep 0’
changed: [127.0.0.1] => (item=01) => {
“changed”: true,
“instance_ids”: [
“i-4321”
],
“instances”: [
{
“ami_launch_index”: “0”,
“architecture”: “x86_64”,
“block_device_mapping”: {
“/dev/xvda”: {
“delete_on_termination”: false,
“status”: “attached”,
“volume_id”: “vol-0dc3d26399128d547”
}
},
“dns_name”: “ec2.amazonaws.com”,
“ebs_optimized”: false,
“groups”: {
“sg-ca0feb83”: “default”
},
“hypervisor”: “xen”,
“id”: “i-1234”,
“image_id”: “ami-b14ba7a7”,
“instance_type”: “t2.micro”,
“kernel”: null,
“key_name”: “key-pair”,
“launch_time”: “2018-05-07T17:59:48.000Z”,
“placement”: “us-east-1b”,
“private_dns_name”: “ip-10-0-1-185.ec2.internal”,
“private_ip”: “10.0.1.185”,
“public_dns_name”: “ec2.amazonaws.com”,
“public_ip”: “1.2.3.4”,
“ramdisk”: null,
“region”: “us-east-1”,
“root_device_name”: “/dev/xvda”,
“root_device_type”: “ebs”,
“state”: “running”,
“state_code”: 16,
“tags”: {
“Name”: “m-01”
},
“tenancy”: “default”,
“virtualization_type”: “hvm”
}
],
“invocation”: {
“module_args”: {
“assign_public_ip”: true,
“aws_access_key”: null,
“aws_secret_key”: null,
“count”: 1,
“count_tag”: null,
“ebs_optimized”: false,
“ec2_url”: null,
“exact_count”: null,
“group”: null,
“group_id”: null,
“id”: null,
“image”: “ami-b14ba7a7”,
“instance_ids”: null,
“instance_initiated_shutdown_behavior”: null,
“instance_profile_name”: null,
“instance_tags”: {
“Name”: “m-01”
},
“instance_type”: “t2.micro”,
“kernel”: null,
“key_name”: “key-pair”,
“monitoring”: true,
“network_interfaces”: null,
“placement_group”: null,
“private_ip”: null,
“profile”: null,
“ramdisk”: null,
“region”: “us-east-1”,
“security_token”: null,
“source_dest_check”: true,
“spot_launch_group”: null,
“spot_price”: null,
“spot_type”: “one-time”,
“spot_wait_timeout”: “600”,
“state”: “present”,
“tenancy”: “default”,
“termination_protection”: null,
“user_data”: null,
“validate_certs”: true,
“volumes”: [
{
“device_name”: “/dev/xvda”,
“volume_size”: 8
}
],
“vpc_subnet_id”: “subnet-83fe1ae4”,
“wait”: true,
“wait_timeout”: “600”,
“zone”: null
}
},
“item”: “01”,
“tagged_instances”:
}
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/cloud/amazon/ec2.py

changed: [127.0.0.1] => (item=02) => {
“changed”: true,
“instance_ids”: [
“i-1234”
],
“instances”: [
{
“ami_launch_index”: “0”,
“architecture”: “x86_64”,
“block_device_mapping”: {
“/dev/xvda”: {
“delete_on_termination”: false,
“status”: “attached”,
“volume_id”: “vol-0ea97c86bb8ade75b”
}
},
“dns_name”: “ec2.amazonaws.com”,
“ebs_optimized”: false,
“groups”: {
“sg-ca0feb83”: “default”
},
“hypervisor”: “xen”,
“id”: “i-1234”,
“image_id”: “ami-b14ba7a7”,
“instance_type”: “t2.micro”,
“kernel”: null,
“key_name”: “key-pair”,
“launch_time”: “2018-05-07T18:00:10.000Z”,
“placement”: “us-east-1b”,
“private_dns_name”: “ip-10-0-1-33.ec2.internal”,
“private_ip”: “10.0.1.33”,
“public_dns_name”: “ec2.amazonaws.com”,
“public_ip”: “1.2.3.4”,
“ramdisk”: null,
“region”: “us-east-1”,
“root_device_name”: “/dev/xvda”,
“root_device_type”: “ebs”,
“state”: “running”,
“state_code”: 16,
“tags”: {
“Name”: “m-02”
},
“tenancy”: “default”,
“virtualization_type”: “hvm”
}
],
“invocation”: {
“module_args”: {
“assign_public_ip”: true,
“aws_access_key”: null,
“aws_secret_key”: null,
“count”: 1,
“count_tag”: null,
“ebs_optimized”: false,
“ec2_url”: null,
“exact_count”: null,
“group”: null,
“group_id”: null,
“id”: null,
“image”: “ami-b14ba7a7”,
“instance_ids”: null,
“instance_initiated_shutdown_behavior”: null,
“instance_profile_name”: null,
“instance_tags”: {
“Name”: “m-02”
},
“instance_type”: “t2.micro”,
“kernel”: null,
“key_name”: “key-pair”,
“monitoring”: true,
“network_interfaces”: null,
“placement_group”: null,
“private_ip”: null,
“profile”: null,
“ramdisk”: null,
“region”: “us-east-1”,
“security_token”: null,
“source_dest_check”: true,
“spot_launch_group”: null,
“spot_price”: null,
“spot_type”: “one-time”,
“spot_wait_timeout”: “600”,
“state”: “present”,
“tenancy”: “default”,
“termination_protection”: null,
“user_data”: null,
“validate_certs”: true,
“volumes”: [
{
“device_name”: “/dev/xvda”,
“volume_size”: 8
}
],
“vpc_subnet_id”: “subnet-83fe1ae4”,
“wait”: true,
“wait_timeout”: “600”,
“zone”: null
}
},
“item”: “02”,
“tagged_instances”:
}

`

i’ve tried everything i’ve seen searching around, but nothing seems to work…

Help is GREATLY appreciated!!

David