I'm currently working on a playbook to create a K8s cluster on Nutanix Prism Central. Everything run smoothly but i face an issue while a VLAN exists on one or more clusters.
In my case, a VLAN is represented by its name but also its UUID (this one can be retrived into metadata on every index inside entities[]).
As a VLAN may exists many times (cause it's configured on different clusters) it means the UUID value may differs on metadata {} but never its name. Below here's the result i got :
ok: [localhost] => {
"msg": {
"changed": false,
"error": null,
"failed": false,
"response": {
"api_version": "3.1",
"entities": [
{
"metadata": {
"categories": {},
"categories_mapping": {},
"creation_time": "2023-03-08T10:11:44Z",
"kind": "subnet",
"last_update_time": "2023-03-08T10:11:44Z",
"spec_hash": "00000000000000000000000000000000000000000000000000",
"spec_version": 0,
"uuid": "aaaa-bbbb-cccc-dddddd"
},
"spec": {
"cluster_reference": {
"kind": "cluster",
"name": "Cluster02",
"uuid": "123123-123123-123123"
},
"name": "MY-VLAN",
"resources": {
"subnet_type": "VLAN",
"virtual_switch_uuid": "321-321-321-321-321",
"vlan_id": 66,
"vswitch_name": "br0"
}
},
"status": {
"cluster_reference": {
"kind": "cluster",
"name": "Cluster02",
"uuid": "123123-123123-123123"
},
"name": "MY-VLAN",
"resources": {
"ip_usage_stats": {
"num_macs": 0
},
"subnet_type": "VLAN",
"virtual_switch_uuid": "321-321-321-321-321",
"vlan_id": 66,
"vswitch_name": "br0"
},
"state": "COMPLETE"
}
},
{
"metadata": {
"categories": {},
"categories_mapping": {},
"creation_time": "2023-03-08T10:11:42Z",
"kind": "subnet",
"last_update_time": "2023-03-08T10:11:42Z",
"spec_hash": "00000000000000000000000000000000000000000000000000",
"spec_version": 0,
"uuid": "999-999-999-999-999"
},
"spec": {
"cluster_reference": {
"kind": "cluster",
"name": "Cluster01",
"uuid": "0005f64b-e395-8cc2-16af-88e9a456e31a"
},
"name": "MY-VLAN",
"resources": {
"subnet_type": "VLAN",
"virtual_switch_uuid": "d4f9ed4f-72c3-4ad0-8223-070fba6a9aea",
"vlan_id": 66,
"vswitch_name": "br0"
}
},
"status": {
"cluster_reference": {
"kind": "cluster",
"name": "Cluster01",
"uuid": "0005f64b-e395-8cc2-16af-88e9a456e31a"
},
"name": "MY-VLAN",
"resources": {
"ip_usage_stats": {
"num_macs": 0
},
"subnet_type": "VLAN",
"virtual_switch_uuid": "d4f9ed4f-72c3-4ad0-8223-070fba6a9aea",
"vlan_id": 66,
"vswitch_name": "br0"
},
"state": "COMPLETE"
}
}
}
}
}
At the moment, i know how to manually retrieve the UUID if I know the index number by having a task like :
- name: Get Network
ntnx_subnets_info:
filter:
#subnet_type: "VLAN"
name: "MY-VLAN"
kind: subnet
register: result
ignore_errors: True
- name: output of identified network
debug:
msg: '{{ result.response.entities[0].metadata.uuid }}'
But i'm currently not able to get the UUID on a dedicated cluster. For example, if I need to retrieve vlan uuid from Cluster01 , i have to select '{{ result.response.entities[1].metadata.uuid }}'
Does someone knows if it possible to dynamically retrieve a value, based on a nested property (in my case spec.cluster_reference.name) ?
Thanks a lot !
I think you could use the
selectattr
filter along withmap
You could retrieve the UUID of the VLAN like that: