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?
--
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/ab47c7b3-e14d-41bb-8046-c6dbcf2abea8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.