# set\_fact, map command combination returning 'undefined'

**URL:** <https://forum.ansible.com/t/set-fact-map-command-combination-returning-undefined/27187>\
**Category:** Ansible Project\
**Created:** [April 4, 2018, 1:45pm UTC](https://forum.ansible.com/t/set-fact-map-command-combination-returning-undefined/27187 "2018-04-04T13:45:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Mirsky](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@Gregory\_Mirsky](https://forum.ansible.com/u/Gregory_Mirsky)\
**Post date:** [April 4, 2018, 1:45pm UTC](https://forum.ansible.com/t/set-fact-map-command-combination-returning-undefined/27187/1 "2018-04-04T13:45:39Z")

</div>

I am able to successfully execute Ansible module **ec2\_vpc\_subnet\_facts** and register the output into a variable, **subnet\_facts**.

I am using Ansible version 2.5.0and python version = 2.7.14

I am able to check that subnet\_facts contains the proper information using:

> - name: Debug for subnet\_facts
> 
> debug:
> 
> var: subnet\_facts
> 
> tags:
> 
> - vpc\_create

I am looking to create a list of subnet\_ids from the **subnet\_facts.results.subnets.id** attribute

The set\_fact example from the Ansible module documentation page ([http://docs.ansible.com/ansible/latest/modules/ec2\_vpc\_subnet\_facts\_module.html](http://docs.ansible.com/ansible/latest/modules/ec2_vpc_subnet_facts_module.html)) throws an error. This is what is on the documentation page:

> - set\_fact:
> 
> subnet\_ids: “{{ subnet\_facts.subnets|map(attribute=‘id’)|list }}”

So far, I’ve managed to play around with the statement to get it to work (see permutations below) but now I get ‘undefined” as the output.

- name: Set subnet\_ids fact

set\_fact:

#subnet\_ids: “{{ subnet\_facts.results|map(attribute=‘id’)|list }}”

subnet\_ids: “{{ subnet\_facts.results|selectattr(‘subnets’)|map(attribute=‘id’)|list }}”

#subnet\_ids: “{{ subnet\_facts.results|map(attribute=‘subnets’)|map(attribute=‘id’)|list }}”

#subnet\_ids: “{{ subnet\_facts|selectattr(‘results.subnets’)|map(attribute=‘id’)|list }}”

- name: Debug for subnet\_ids

debug:

var: subnet\_ids

tags:

- vpc\_create

ok: [localhost] =\> {

“ansible\_facts”: {

“subnet\_ids”: “[Undefined, Undefined, Undefined]”

},

“changed”: false

}

I think I am at the “can’t see the forest for the trees” stage and I need the proverbial slap upside the head to show me what I am doing wrong. Any ideas? Suggestions?
