convert yaml file into jinja

Hi Folks:

I want to know if there is a way to extract from a yaml file the disk information in order to pass it into jinja2 template. I got the following:

{
“ansible_facts”: {
“ansible_disks”: [
{
“bootable”: false,
“bus_type”: “SAS”,
“clustered”: false,
“firmware_version”: "1.0 ",
“friendly_name”: “VMware Virtual disk SCSI Disk Device”,
“guid”: null,
“location”: “PCIROOT(0)#PCI(1500)#PCI(0000)#SAS(P00T01L00)”,
“manufacturer”: "VMware ",
“model”: "Virtual disk ",
“number”: 1,
“operational_status”: “Offline”,
“partition_count”: 0,
“partition_style”: “RAW”,
“path”: “\\?\scsi#disk&ven_vmware&prod_virtual_disk#5&174a0eaf&0&000100#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}”,
“physical_disk”: {
“allocated_size”: 0,
“bus_type”: “SAS”,
“can_pool”: true,
“device_id”: “1”,
“firmware_version”: "1.0 ",
“friendly_name”: “PhysicalDisk1”,
“health_status”: “Healthy”,
“indication_enabled”: null,
“manufacturer”: "VMware ",
“media_type”: “UnSpecified”,
“model”: "Virtual disk ",
“object_id”: “{1}\\TCGNY-NE-DRVN2\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{98093284-f7ed-11e8-80b5-806e6f6e6963}:PD:{31d8233c-98dd-e50b-be04-4efda565d7a9}"”,
“operational_status”: “OK”,
“partial”: false,
“physical_location”: null,
“serial_number”: “6000c29300845e830d442c17cbfff618”,
“size”: 128849018880,
“spindle_speed”: 4294967295,
“supported_usages”: {
“Count”: 5,
“value”: [
“Auto-Select”,
“Manual-Select”,
“Hot Spare”,
“Retired”,
“Journal”
]
},
“unique_id”: “6000C29300845E830D442C17CBFFF618”,
“usage_type”: “Auto-Select”
},
“read_only”: true,
“sector_size”: 512,
“serial_number”: “6000c29300845e830d442c17cbfff618”,
“size”: 128849018880,
“system_disk”: false,
“unique_id”: “6000C29300845E830D442C17CBFFF618”
},
{
“bootable”: true,
“bus_type”: “SAS”,
“clustered”: false,
“firmware_version”: "1.0 ",
“friendly_name”: “VMware Virtual disk SCSI Disk Device”,
“guid”: null,
“location”: “PCIROOT(0)#PCI(1500)#PCI(0000)#SAS(P00T00L00)”,
“manufacturer”: "VMware ",
“model”: "Virtual disk ",
“number”: 0,
“operational_status”: “Online”,
“partition_count”: 2,
“partition_style”: “MBR”,
“partitions”: [
{
“access_paths”: [
“\\?\Volume{9809328a-f7ed-11e8-80b5-806e6f6e6963}\”
],
“active”: true,
“drive_letter”: null,
“guid”: null,
“hidden”: false,
“mbr_type”: 7,
“number”: 1,
“offset”: 1048576,
“shadow_copy”: false,
“size”: 367001600,
“transition_state”: 1,
“type”: “IFS”,
“volumes”: [
{
“allocation_unit_size”: 4096,
“drive_type”: “Fixed”,
“health_status”: “Healthy”,
“label”: “System Reserved”,
“object_id”: “\\?\Volume{9809328a-f7ed-11e8-80b5-806e6f6e6963}\”,
“path”: “\\?\Volume{9809328a-f7ed-11e8-80b5-806e6f6e6963}\”,
“size”: 366997504,
“size_remaining”: 63823872,
“type”: “NTFS”
}
]
},
{
“access_paths”: [
“C:\”,
“\\?\Volume{9809328b-f7ed-11e8-80b5-806e6f6e6963}\”
],
“active”: false,
“drive_letter”: “C”,
“guid”: null,
“hidden”: false,
“mbr_type”: 7,
“number”: 2,
“offset”: 368050176,
“shadow_copy”: false,
“size”: 53317992448,
“transition_state”: 1,
“type”: “IFS”,
“volumes”: [
{
“allocation_unit_size”: 4096,
“drive_type”: “Fixed”,
“health_status”: “Healthy”,
“label”: “”,
“object_id”: “\\?\Volume{9809328b-f7ed-11e8-80b5-806e6f6e6963}\”,
“path”: “\\?\Volume{9809328b-f7ed-11e8-80b5-806e6f6e6963}\”,
“size”: 53317988352,
“size_remaining”: 36704559104,
“type”: “NTFS”
}
]
}
],
“path”: “\\?\scsi#disk&ven_vmware&prod_virtual_disk#5&174a0eaf&0&000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}”,
“physical_disk”: {
“allocated_size”: 53687091200,
“bus_type”: “SAS”,
“can_pool”: false,
“cannot_pool_reason”: “Insufficient Capacity”,
“device_id”: “0”,
“firmware_version”: "1.0 ",
“friendly_name”: “PhysicalDisk0”,
“health_status”: “Healthy”,
“indication_enabled”: null,
“manufacturer”: "VMware ",
“media_type”: “UnSpecified”,
“model”: "Virtual disk ",
“object_id”: “{1}\\TCGNY-NE-DRVN2\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{98093284-f7ed-11e8-80b5-806e6f6e6963}:PD:{cc8752a3-5b18-e7bf-a2a9-3f2776bd9926}"”,
“operational_status”: “OK”,
“partial”: true,
“physical_location”: null,
“serial_number”: “6000c2945d2a5f3a9f5d4e73168d86e4”,
“size”: 53687091200,
“spindle_speed”: 4294967295,
“supported_usages”: {
“Count”: 5,
“value”: [
“Auto-Select”,
“Manual-Select”,
“Hot Spare”,
“Retired”,
“Journal”
]
},
“unique_id”: “6000C2945D2A5F3A9F5D4E73168D86E4”,
“usage_type”: “Auto-Select”
},
“read_only”: false,
“sector_size”: 512,
“serial_number”: “6000c2945d2a5f3a9f5d4e73168d86e4”,
“size”: 53687091200,
“system_disk”: true,
“unique_id”: “6000C2945D2A5F3A9F5D4E73168D86E4”
}
]
},
“changed”: false
}

Someone know the way?.

Thanks in advance

Federico

You can access ansible_facts in a jinja2 template like you would in a
playbook:

{{ ansible_facts['disks'][0]['size'] }}

- Sebastian