Been scratching my head with this one. Even digging into the jmespath docs, but really stuck.
http://jmespath.org/specification.html#map
I have a bunch of subnets, which I get back with :-
-
name: Cluster create | Get Private Subnet facts
ec2_vpc_subnet_facts:
filters:
vpc-id: “{{ vpc_id }}”
“tag:Name”: “private-*”
register: result -
name: Cluster create | debug result of private ec2_vpc_subnet_facts
debug:
var: result
This returns with :–
TASK [k8s_cluster : Cluster create | debug result of private ec2_vpc_subnet_facts] ***
ok: [localhost] => {
“result”: {
“changed”: false,
“failed”: false,
“subnets”: [
{
“assign_ipv6_address_on_creation”: false,
“availability_zone”: “eu-west-1c”,
“availability_zone_id”: “euw1-az3”,
“available_ip_address_count”: 46,
“cidr_block”: “172.172.172.64/26”,
“default_for_az”: false,
“id”: “subnet-fefefefe”,
“ipv6_cidr_block_association_set”: ,
“map_public_ip_on_launch”: false,
“owner_id”: “987654321”,
“state”: “available”,
“subnet_arn”: “arn:aws:ec2:eu-west-1:987654321:subnet/subnet-fefefefe”,
“subnet_id”: “subnet-fefefefe”,
“tags”: {
…
},
“vpc_id”: “vpc-cececece”
},
{
(I changed the subnet IDs and VPC ID. )
I’ve been trying something along the line of :-
- set_fact:
az_to_private_sub: “{{ result.subnets | map(‘subnet.availability_zone’: ‘subnets.subnet_id’) ) }}”
However, no joy.
I managed to extract the subnet IDs, using :-
- set_fact:
az_to_private_sub: “{{ result | json_query(‘subnets[*].subnet_id’ | map() ) }}”
but what I’m trying to achieve needs both the AZ and the subnet ID, like this :-
az_to_private_sub:
eu-west-1a: subnet-aaaaaaaa
eu-west-1b: subnet-bbbbbbbb
eu-west-1c: subnet-cccccccc
az_to_public_sub:
eu-west-1a: subnet-dddddddd
eu-west-1b: subnet-eeeeeeee
eu-west-1c: subnet-ffffffff
Any ideas?