set_fact, map command combination returning 'undefined'

15 views
Skip to first unread message

Gregory Mirsky

unread,
Apr 4, 2018, 9:45:39 AM4/4/18
to Ansible Project

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) 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 }}"

 

Running this


  - name: Debug for subnet_ids

    debug:

      var: subnet_ids

    tags:

      - vpc_create


Yields this


 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?



Reply all
Reply to author
Forward
0 new messages