I've been trying to extract the values for subnet_id from the dictionary 
subnet_facts but keep getting undefined (3 times instead of the values) as 
a return value. I should be getting [subnet-fd6bfa95, subnet-7c8bb031, 
subnet-7c8bb031]

Any ideas?

Below is the local host testbed playbook i've been using trying to get this 
jinja filter to work.


---
> - hosts: local
>   vars:
>     "subnet_facts": {
>                       "changed": false,
>                       "msg": "All items completed",
>                       "results": [
>                           {
>                               "_ansible_ignore_errors": null,
>                               "_ansible_item_result": true,
>                               "_ansible_no_log": false,
>                               "_ansible_parsed": true,
>                               "changed": false,
>                               "failed": false,
>                               "invocation": {
>                                   "module_args": {
>                                       "aws_access_key": 
> "XXXXXXXXXXXXXXXXXXXXX",
>                                       "aws_secret_key": 
> "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
>                                       "ec2_url": null,
>                                       "filters": {
>                                           "tag:Name": 
> "test-subnet-us-east-2a-public",
>                                           "vpc-id": "vpc-1227b97a"
>                                       },
>                                       "profile": null,
>                                       "region": "us-east-2",
>                                       "security_token": null,
>                                       "subnet_ids": [],
>                                       "validate_certs": true
>                                   }
>                               },
>                               "item": "test-subnet-us-east-2a-public",
>                               "subnets": [
>                                   {
>                                       "assign_ipv6_address_on_creation": 
> false,
>                                       "availability_zone": "us-east-2a",
>                                       "available_ip_address_count": 251,
>                                       "cidr_block": "10.0.1.0/24",
>                                       "default_for_az": false,
>                                       "id": "subnet-fd6bfa95",
>                                       "ipv6_cidr_block_association_set": 
> [],
>                                       "map_public_ip_on_launch": true,
>                                       "state": "available",
>                                       "subnet_id": "subnet-fd6bfa95",
>                                       "tags": {
>                                           "DeleteTag": 
> "[email protected]",
>                                           "Name": 
> "test-subnet-us-east-2a-public",
>                                           "SubnetType": "public"
>                                       },
>                                       "vpc_id": "vpc-1227b97a"
>                                   }
>                               ]
>                           },
>                           {
>                               "_ansible_ignore_errors": null,
>                               "_ansible_item_result": true,
>                               "_ansible_no_log": false,
>                               "_ansible_parsed": true,
>                               "changed": false,
>                               "failed": false,
>                               "invocation": {
>                                   "module_args": {
>                                       "aws_access_key": 
> "XXXXXXXXXXXXXXXXXXXXX",
>                                       "aws_secret_key": 
> "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
>                                       "ec2_url": null,
>                                       "filters": {
>                                           "tag:Name": 
> "test-subnet-us-east-2b-public",
>                                           "vpc-id": "vpc-1227b97a"
>                                       },
>                                       "profile": null,
>                                       "region": "us-east-2",
>                                       "security_token": null,
>                                       "subnet_ids": [],
>                                       "validate_certs": true
>                                   }
>                               },
>                               "item": "test-subnet-us-east-2b-public",
>                               "subnets": [
>                                   {
>                                       "assign_ipv6_address_on_creation": 
> false,
>                                       "availability_zone": "us-east-2b",
>                                       "available_ip_address_count": 251,
>                                       "cidr_block": "10.0.2.0/24",
>                                       "default_for_az": false,
>                                       "id": "subnet-6ad01910",
>                                       "ipv6_cidr_block_association_set": 
> [],
>                                       "map_public_ip_on_launch": true,
>                                       "state": "available",
>                                       "subnet_id": "subnet-6ad01910",
>                                       "tags": {
>                                           "DeleteTag": 
> "[email protected]",
>                                           "Name": 
> "test-subnet-us-east-2b-public",
>                                           "SubnetType": "public"
>                                       },
>                                       "vpc_id": "vpc-1227b97a"
>                                   }
>                               ]
>                           },
>                           {
>                               "_ansible_ignore_errors": null,
>                               "_ansible_item_result": true,
>                               "_ansible_no_log": false,
>                               "_ansible_parsed": true,
>                               "changed": false,
>                               "failed": false,
>                               "invocation": {
>                                   "module_args": {
>                                       "aws_access_key": 
> "XXXXXXXXXXXXXXXXXXXXX",
>                                       "aws_secret_key": 
> "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
>                                       "ec2_url": null,
>                                       "filters": {
>                                           "tag:Name": 
> "test-subnet-us-east-2c-public",
>                                           "vpc-id": "vpc-1227b97a"
>                                       },
>                                       "profile": null,
>                                       "region": "us-east-2",
>                                       "security_token": null,
>                                       "subnet_ids": [],
>                                       "validate_certs": true
>                                   }
>                               },
>                               "item": "test-subnet-us-east-2c-public",
>                               "subnets": [
>                                   {
>                                       "assign_ipv6_address_on_creation": 
> false,
>                                       "availability_zone": "us-east-2c",
>                                       "available_ip_address_count": 251,
>                                       "cidr_block": "10.0.3.0/24",
>                                       "default_for_az": false,
>                                       "id": "subnet-7c8bb031",
>                                       "ipv6_cidr_block_association_set": 
> [],
>                                       "map_public_ip_on_launch": true,
>                                       "state": "available",
>                                       "subnet_id": "subnet-7c8bb031",
>                                       "tags": {
>                                           "DeleteTag": 
> "[email protected]",
>                                           "Name": 
> "test-subnet-us-east-2c-public",
>                                           "SubnetType": "public"
>                                       },
>                                       "vpc_id": "vpc-1227b97a"
>                                   }
>                               ]
>                           }
>                       ]
>                   }
>   tasks:
>   - name: Debug for subnet_facts...
>     debug:
>       var: subnet_facts
>   - name: Debug for subnet_facts.results.subnets.subnet_id parse
>     debug:
>       var: "{{ subnet_facts | selectattr('results.subnets.id') | list }}"
>       #var: "{{ 
> subnet_facts.results|map(attribute='subnets')|map(attribute='subnet_id')|list 
> }}"
>       #var: "{{ subnet_facts.results|map(attribute='subnets.subnet_id')| 
> list }}"
>       #var: "{{ subnet_facts.results | selectattr('subnets') |  
> map(attribute='subnet_id') | list }}"
>       #var: "{{ subnet_facts|json_query('results[*].subnets.subnet_id') }}"
>   - meta: end_play


-- 
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/9ab5a425-3385-4650-91ba-fbc307d5aa97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to