On 23.03.2017 05:09, Bhavin Parmar wrote:
*Same way another looping issue is as follow (actual code):*

It's no issue here, it's working as designed.
To understand, we need to now what you would expect.


  - name: "Task 2: Fetch EC2 details"
    ec2_remote_facts:
      aws_access_key: '{{ AwsAccesskey }}'
      aws_secret_key: '{{ AwsSecretkey }}'
      region: '{{ region }}'
      filters:
        instance_id: '{{ item }}'
    register: ec2_hosts
    with_items: "{{ awsec2id }}"

The output of is registered in variable ec2_hosts


  - debug: var=ec2_hosts

And the output is a list, one for each item, in ec2_hosts.results.
So the output below is as expected.


*Output registered variable ec2_hosts, follow:*
ok: [localhost] => {
    "changed": false,
    "ec2_hosts": {
        "changed": false,
        "msg": "All items completed",
        "results": [
            {
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "_ansible_parsed": true,
                "changed": false,
                "instances": [
                    {
                        "ami_launch_index": "0",
                        "architecture": "x86_64",
                        "block_device_mapping": [
                            {
"attach_time": "2017-03-17T08:02:13.000Z",
                                "delete_on_termination": false,
                                "device_name": "/dev/xvda",
                                "status": "attached",
                                "volume_id": "vol-0573516d4320XXXXX"
                            },
                            {
"attach_time": "2017-03-21T08:32:27.000Z",
                                "delete_on_termination": false,
                                "device_name": "/dev/xvdl",
                                "status": "attached",
                                "volume_id": "vol-07556df02e90XXXXX"
                            }
                        ],
                        "client_token": "IQNIH14887952XXXXX",
                        "ebs_optimized": false,
                        "groups": [
                            {
                                "id": "sg-dbcXXXXX",
                                "name": "launch-wizard-14"
                            }
                        ],
                        "hypervisor": "xen",
                        "id": "i-0003df8d26bXXXXX",
                        "image_id": "ami-0b33XXXXX",
                        "instance_profile": null,
                        "interfaces": [
                            {
                                "id": "eni-8fdfbXXXXX",
                                "mac_address": "0e:df:73:4c:67:e6"
                            }
                        ],
                        "kernel": null,
                        "key_name": "XXXXX",
                        "launch_time": "2017-03-21T04:02:10.000Z",
                        "monitoring_state": "disabled",
                        "persistent": false,
                        "placement": {
                            "tenancy": "default",
                            "zone": "us-east-1c"
                        },
                        "private_dns_name": "ip-XXXXX.ec2.internal",
                        "private_ip_address": "172.XXXXX",
                        "public_dns_name":
"ec2-XXXXX-156.compute-1.amazonaws.com",
                        "public_ip_address": "54.89.XXXXX",
                        "ramdisk": null,
                        "region": "us-east-1",
                        "requester_id": null,
                        "root_device_type": "ebs",
                        "source_destination_check": "true",
                        "spot_instance_request_id": null,
                        "state": "running",
                        "tags": {
                            "Name": "XXXXX"
                        },
                        "virtualization_type": "hvm",
                        "vpc_id": "vpc-76XXXXX"
                    }
                ],
                "invocation": {
                    "module_args": {
                        "aws_access_key": "AKIAIGKMK7EXXXXX",
                        "aws_secret_key": "VALUE_SPECIFIED_IN_NOXXXXX",
                        "ec2_url": null,
                        "filters": {
                            "instance_id": "i-0003df8d26XXXXX"
                        },
                        "profile": null,
                        "region": "us-east-1",
                        "security_token": null,
                        "validate_certs": true
                    }
                },
                "item": "i-0003df8d26b5XXXXX"
            },
            {
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "_ansible_parsed": true,
                "changed": false,
                "instances": [
                    {
                        "ami_launch_index": "0",
                        "architecture": "x86_64",
                        "block_device_mapping": [
                            {
"attach_time": "2017-03-21T08:32:38.000Z",
                                "delete_on_termination": false,
                                "device_name": "/dev/xvdl",
                                "status": "attached",
                                "volume_id": "vol-0118435137XXXXX"
                            },
                            {
"attach_time": "2017-03-22T08:28:47.000Z",
                                "delete_on_termination": false,
                                "device_name": "/dev/sda1",
                                "status": "attached",
                                "volume_id": "vol-0e0516ea96XXXXX"
                            }
                        ],
                        "client_token": "CrBZB1489737XXXXX",
                        "ebs_optimized": false,
                        "groups": [
                            {
                                "id": "sg-13d8076c",
                                "name": "launch-wizard-19"
                            }
                        ],
                        "hypervisor": "xen",
                        "id": "i-04452f010e4cXXXXX",
                        "image_id": "ami-2051XXXXX",
                        "instance_profile": null,
                        "interfaces": [
                            {
                                "id": "eni-4c0efXXXXX",
                                "mac_address": "0e:d9:48:XXXXX"
                            }
                        ],
                        "kernel": null,
                        "key_name": "bparmaXXXXX",
                        "launch_time": "2017-03-22T10:23:26.000Z",
                        "monitoring_state": "disabled",
                        "persistent": false,
                        "placement": {
                            "tenancy": "default",
                            "zone": "us-east-1c"
                        },
"private_dns_name": "ip-172-31-XXXXX.ec2.internal",
                        "private_ip_address": "172.31XXXXX",
                        "public_dns_name":
"ec2-34-207-XXXXX.compute-1.amazonaws.com",
                        "public_ip_address": "34.207.XXXXX",
                        "ramdisk": null,
                        "region": "us-east-1",
                        "requester_id": null,
                        "root_device_type": "ebs",
                        "source_destination_check": "true",
                        "spot_instance_request_id": null,
                        "state": "running",
                        "tags": {
                            "Name": "XXXXX"
                        },
                        "virtualization_type": "hvm",
                        "vpc_id": "vpc-76b6XXXXX"
                    }
                ],
                "invocation": {
                    "module_args": {
                        "aws_access_key": "AKIAIGKMK7E3O2RXXXXX",
"aws_secret_key": "VALUE_SPECIFIED_IN_NO_XXXXX",
                        "ec2_url": null,
                        "filters": {
                            "instance_id": "i-04452f010XXXXX"
                        },
                        "profile": null,
                        "region": "us-east-1",
                        "security_token": null,
                        "validate_certs": true
                    }
                },
                "item": "i-04452f010e4cXXXXX"
            }
        ]
    }
}


--
Kai Stian Olstad

--
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/6f0d896b3d21b465d26a7142f85c117f%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to