ec2.results is not being defined

202 views
Skip to first unread message

Eric S

unread,
May 23, 2016, 12:22:05 PM5/23/16
to Ansible Project
ansible ver=2.0.2

When I'm registering the ec2 var isn't results suppose to be automatically defined as the results of what was registered in the variable.  I'm getting this when trying to debug the ec2.results var:
TASK [debug ec2 var] ***********************************************************
Monday 23 May 2016  11:14:18 -0500 (0:00:38.587)       0:00:43.306 ************
ok: [aaa-frs-ans-test1] => {
    "ec2.results": "VARIABLE IS NOT DEFINED!"
}
ok: [aaa-frs-ans-test2] => {
    "ec2.results": "VARIABLE IS NOT DEFINED!"
}
Here's my creation task:
- hosts: ec2_instances
  connection: local
  gather_facts: true
  tasks:
    - name: Launch Instance
      ec2:
        group_id: "{{ hostvars[inventory_hostname].group_id }}"
        instance_type: 't2.micro'
        image: "{{ hostvars[inventory_hostname].image }}"
        wait: true
        region: 'us-east-1'
        keypair: 'QA_KEYPAIR'
        vpc_subnet_id: "{{ subnet }}"
        instance_tags: "{{ hostvars[inventory_hostname].tags }}"
      register: ec2

They launch fine and if I debug ec2.instances I get all the info from that variable.  Also when I debug just ec2 I get all the info as well.  I did see though that when I debug just ec2 there isn't a .results section but again I thought that was a default var.

Johannes Kastl

unread,
May 23, 2016, 1:19:00 PM5/23/16
to ansible...@googlegroups.com
On 23.05.16 18:22 Eric S wrote:
> ansible ver=2.0.2
>
> When I'm registering the ec2 var isn't results suppose to be automatically
> defined as the results of what was registered in the variable. I'm getting
> this when trying to debug the ec2.results var:

Why don't you debug the var itself and look what subelements there are?

As to why there is no results subelement I have no clue...

Johannes

signature.asc

Eric S

unread,
May 23, 2016, 1:23:23 PM5/23/16
to Ansible Project
I did that and there isn't the results element.  I've seen a lot of people using that, so not sure why its not being set.

Eric S

unread,
May 24, 2016, 1:40:10 PM5/24/16
to Ansible Project
does anyone know or have a clue why ec2.results wouldn't be populated?

Matt Martz

unread,
May 24, 2016, 1:43:54 PM5/24/16
to ansible...@googlegroups.com
I think what you want is `ec2.instances` instead of `ec2.results`.

You will likely only have the `results` sub key if you are also using something like `with_items` or `with_subelements`.  See http://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop for an explanation of register + looping, where it creates a `results` key.

On Tue, May 24, 2016 at 12:40 PM, Eric S <erics...@gmail.com> wrote:
does anyone know or have a clue why ec2.results wouldn't be populated?

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9d992af6-de61-468b-b92e-a144600c8129%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Josh Smift

unread,
May 24, 2016, 1:48:09 PM5/24/16
to ansible...@googlegroups.com
ES> does anyone know or have a clue why ec2.results wouldn't be populated?

Random shots in the dark:

- Is 'ec2' as a variable name clashing with the module name in some way?
What if you do 'register: foo' instead?

- What *is* in 'foo', if you 'debug: var=foo' it? Is it everything you'd
expect to see *except* the 'results' element, or something totally different?

Actually, backing up a step: What do you expect to see in the results
element, and why? Is the information that you're looking for somewhere
else in the variable?

-Josh (j...@care.com)

(apologies for the automatic corporate disclaimer that follows)




This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

Eric S

unread,
May 24, 2016, 2:15:52 PM5/24/16
to Ansible Project
i also registered ec2_info as a var just to play around and it has the same results but it does display: *sorry for the long output*
ok: [aaa-frs-ans-test3] => {
    "ec2_info": {
        "changed": true,
        "instance_ids": [
            "i-790418fe"
        ],
        "instances": [
            {
                "ami_launch_index": "0",
                "architecture": "x86_64",
                "block_device_mapping": {
                    "/dev/sda1": {
                        "delete_on_termination": true,
                        "status": "attached",
                        "volume_id": "vol-0c034fa7"
                    }
                },
                "dns_name": "",
                "ebs_optimized": false,
                "groups": {
                    "sg-7c538d04": "fsr-allow-all"
                },
                "hypervisor": "xen",
                "id": "i-790418fe",
                "image_id": "ami-3683605b",
                "instance_type": "t2.micro",
                "kernel": null,
                "key_name": "FSR_DEV_QA_KEYPAIR",
                "launch_time": "2016-05-24T18:13:10.000Z",
                "placement": "us-east-1a",
                "private_dns_name": "ip-10-196-135-193.ec2.internal",
                "private_ip": "10.196.135.193",
                "public_dns_name": "",
                "public_ip": null,
                "ramdisk": null,
                "region": "us-east-1",
                "root_device_name": "/dev/sda1",
                "root_device_type": "ebs",
                "state": "running",
                "state_code": 16,
                "tags": {
                    "Env": "Dev",
                    "Name": "aaa-fsr-ans-test2"
                },
                "tenancy": "default",
                "virtualization_type": "hvm"
            }
        ],
        "tagged_instances": []
    }
}
for each of the hosts, meaning 3 hosts.

Eric S

unread,
May 25, 2016, 3:23:48 PM5/25/16
to Ansible Project
Matt that makes sense.  I did try ec2.instances but it is only add the first host not all three.  I did do a debug on ec2 and ec2.instances and it is showing all 3 instances that I'm turning up.  Any ideas on that.  This is only  happening on the add_hosts module.  I have a wait for ssh to come up task and ec2.instances var are giving me an ok for all three.

Josh Smift

unread,
May 25, 2016, 4:17:17 PM5/25/16
to ansible...@googlegroups.com
ES> I did try ec2.instances but it is only add the first host not all
ES> three. I did do a debug on ec2 and ec2.instances and it is showing all
ES> 3 instances that I'm turning up. Any ideas on that. This is only
ES> happening on the add_hosts module. I have a wait for ssh to come up
ES> task and ec2.instances var are giving me an ok for all three.

I tried with this trivial playbook, and it worked fine:

- hosts: localhost
vars:
myhosts: [apple, banana, cherry]
tasks:
- debug: var=myhosts
- add_host: name={{ item }} groups=mygroup
with_items: myhosts
- debug: var=groups['mygroup']

I got

TASK: [debug var=groups['mygroup']]
*******************************************
ok: [localhost] => {
"var": {
"groups['mygroup']": [
"apple",
"banana",
"cherry"
]
}
}

as expected. Ansible 1.9.4 if it matters.

Does it work for you if you try a case like this that isn't ec2.instances?
If so, maybe there's something about the way ec2.instances is structured
that isn't what you expect, like it's a dict of lists of dicts of dicts of
lists rather than a list of dicts of dicts of lists, or something. :^)
Reply all
Reply to author
Forward
0 new messages