Спасибо заранее. Я застрял в своей Ansible пьесе со сравнением двух списков:
мои отладки показывают, что я набираю правильный серийный номер, если я запускаю их независимо.
- name: set P drive (vmware disk 2:1)
set_fact:
p_disk_number: "{{ item.1.number }}"
loop: "{{ vmware_disk_info.guest_disk_info.keys() | product(ansible_facts.disks) | list }}"
loop_control:
label: "{{ item.1.physical_disk.serial_number }}"
when:
- item.1.physical_disk.serial_number is match(vmware_disk_info.guest_disk_info[item.0|quote].backing_uuid)
Я пытаюсь получить этот результат:
Я ищу данные в ansible факты о диске p_disk_number: 2
Я застрял при сравнении 2-й набор с - в нем - когда 6000c294c8f42faaf8c0a6488a4ebb7d выполняет поиск 6000C294-c8f4-2faa-f8c0-a6488a4ebb7d сравнивает размер с Capacity_in_bytes - когда (54760833024) == (также 54760833024) сравнивают его с «гостями»: controller_bus_number ": 1,
вывод guest_disk_info:
{
"guest_disk_info": {
"0": {
"controller_type": "paravirtual",
"backing_filename": "",
"capacity_in_kb": 62914560,
"backing_datastore": "",
"backing_eagerlyscrub": true,
"backing_writethrough": false,
"key": 2000,
"capacity_in_bytes": 64424509440,
"label": "Hard disk 1",
"backing_uuid": "6000C294-c8f4-2faa-f8c0-a6488a4ebb7d",
"backing_thinprovisioned": false,
"backing_type": "FlatVer2",
"summary": "62,914,560 KB",
"controller_bus_number": 0,
"controller_key": 1000,
"unit_number": 0
},
"1": {
"controller_type": "paravirtual",
"backing_filename": "",
"capacity_in_kb": 53477376,
"backing_datastore": "",
"backing_eagerlyscrub": true,
"backing_writethrough": false,
"key": 2017,
"capacity_in_bytes": 54760833024,
"label": "Hard disk 2",
"backing_uuid": "6000C294-6906-de68-7f94-c007b164b5f3",
"backing_thinprovisioned": false,
"backing_type": "FlatVer2",
"summary": "53,477,376 KB",
"controller_bus_number": 1,
"controller_key": 1001,
"unit_number": 1
},
"2": {
"controller_type": "paravirtual",
"backing_filename": "",
"capacity_in_kb": 11534336,
"backing_datastore": "",
"backing_eagerlyscrub": true,
"backing_writethrough": false,
"key": 2033,
"capacity_in_bytes": 11811160064,
"label": "Hard disk 3",
"backing_uuid": "6000C29e-5b0f-99e5-9431-24559cb9d9c2",
"backing_thinprovisioned": false,
"backing_type": "FlatVer2",
"summary": "11,534,336 KB",
"controller_bus_number": 2,
"controller_key": 1002,
"unit_number": 1
},
"3": {
"controller_type": "paravirtual",
"backing_filename": "",
"capacity_in_kb": 54525952,
"backing_datastore": "",
"backing_eagerlyscrub": true,
"backing_writethrough": false,
"key": 2049,
"capacity_in_bytes": 55834574848,
"label": "Hard disk 4",
"backing_uuid": "6000C296-d848-0bd4-685d-75901c61d797",
"backing_thinprovisioned": false,
"backing_type": "FlatVer2",
"summary": "54,525,952 KB",
"controller_bus_number": 3,
"controller_key": 1003,
"unit_number": 1
}
},
"_ansible_no_log": false,
"_ansible_delegated_vars": {
"ansible_host": "localhost"
},
"invocation": {
"module_args": {
"username": "",
"datacenter": "",
"uuid": null,
"proxy_host": null,
"hostname": "",
"proxy_port": null,
"folder": null,
"moid": null,
"use_instance_uuid": false,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"validate_certs": false,
"port": 443,
"name": ""
}
},
"changed": false
}
Вывод Ansible дисков:
{
"changed": false,
"ansible_facts": {
"ansible_disks": [
{
"bus_type": "SAS",
"physical_disk": {
"bus_type": "SAS",
"partial": true,
"cannot_pool_reason": "Insufficient Capacity",
"serial_number": "6000c297f6e8648a15aeecd34a4fde16",
"supported_usages": {
"Count": 5,
"value": [
"Auto-Select",
"Manual-Select",
"Hot Spare",
"Retired",
"Journal"
]
},
"firmware_version": "1.0",
"usage_type": "Auto-Select",
"size": 64424509440,
"can_pool": false,
"operational_status": "OK",
"friendly_name": "VMware Virtual disk",
"object_id": "{1}\\\\\\root/Microsoft/Windows/Storage/Providers_v2\\SPACES_PhysicalDisk.ObjectId=\"{c8327f0b-13eb-11e7-a93d-806e6f6e6963}:PD:{aaa05ef3-f43b-04ee-1f8e-09a04de96625}\"",
"health_status": "Healthy",
"unique_id": "6000C297F6E8648A15AEECD34A4FDE16",
"physical_location": "SCSI0",
"media_type": "SSD",
"model": "Virtual disk",
"manufacturer": "VMware",
"spindle_speed": 0,
"device_id": "0",
"indication_enabled": null,
"allocated_size": 64424509440
},
"partition_count": 2,
"partition_style": "MBR",
"unique_id": "6000C297F6E8648A15AEECD34A4FDE16",
"number": 0,
"clustered": false,
"path": "\\\\?\\scsi#disk&ven_vmware&prod_virtual_disk#000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}",
"firmware_version": "1.0 ",
"guid": null,
"size": 64424509440,
"read_only": false,
"sector_size": 512,
"bootable": true,
"partitions": [
{
"transition_state": 1,
"shadow_copy": false,
"number": 1,
"access_paths": [
"\\\\?\\Volume{0beac360-0000-0000-0000-100000000000}\\"
],
"active": true,
"drive_letter": null,
"volumes": [
{
"allocation_unit_size": 4096,
"object_id": "{1}\\\\\\root/Microsoft/Windows/Storage/Providers_v2\\WSP_Volume.ObjectId=\"{c8327f0b-13eb-11e7-a93d-806e6f6e6963}:VO:\\\\?\\Volume{0beac360-0000-0000-0000-100000000000}\\\"",
"label": "System Reserved",
"size_remaining": 173150208,
"health_status": "Healthy",
"drive_type": "Fixed",
"path": "\\\\?\\Volume{0beac360-0000-0000-0000-100000000000}\\",
"type": "NTFS",
"size": 524283904
}
],
"offset": 1048576,
"mbr_type": 7,
"hidden": false,
"guid": null,
"type": "IFS",
"size": 524288000
},
{
"transition_state": 1,
"shadow_copy": false,
"number": 2,
"access_paths": [
"C:\\",
"\\\\?\\Volume{0beac360-0000-0000-0000-501f00000000}\\"
],
"active": false,
"drive_letter": "C",
"volumes": [
{
"allocation_unit_size": 4096,
"object_id": "{1}\\\\\\root/Microsoft/Windows/Storage/Providers_v2\\WSP_Volume.ObjectId=\"{c8327f0b-13eb-11e7-a93d-806e6f6e6963}:VO:\\\\?\\Volume{0beac360-0000-0000-0000-501f00000000}\\\"",
"label": "",
"size_remaining": 47552921600,
"health_status": "Healthy",
"drive_type": "Fixed",
"path": "\\\\?\\Volume{0beac360-0000-0000-0000-501f00000000}\\",
"type": "NTFS",
"size": 63898120192
}
],
"offset": 525336576,
"mbr_type": 7,
"hidden": false,
"guid": null,
"type": "IFS",
"size": 63898124288
}
],
"operational_status": "Online",
"friendly_name": "VMware Virtual disk",
"location": "SCSI0",
"serial_number": "6000c297f6e8648a15aeecd34a4fde16",
"model": "Virtual disk ",
"manufacturer": "VMware ",
"system_disk": true
},
{
"size": 12884901888,
"bus_type": "SAS",
"physical_disk": {
"bus_type": "SAS",
"operational_status": "OK",
"partial": false,
"media_type": "SSD",
"supported_usages": {
"Count": 5,
"value": [
"Auto-Select",
"Manual-Select",
"Hot Spare",
"Retired",
"Journal"
]
},
"usage_type": "Auto-Select",
"firmware_version": "1.0",
"size": 12884901888,
"can_pool": true,
"allocated_size": 2097152,
"friendly_name": "VMware Virtual disk",
"object_id": "{1}\\\\\\root/Microsoft/Windows/Storage/Providers_v2\\SPACES_PhysicalDisk.ObjectId=\"{c8327f0b-13eb-11e7-a93d-806e6f6e6963}:PD:{fce90434-6844-98fc-34a6-eb171149acf0}\"",
"health_status": "Healthy",
"unique_id": "6000C29D4858C95EBED8358D5573436A",
"physical_location": "SCSI3",
"serial_number": "6000c29d4858c95ebed8358d5573436a",
"model": "Virtual disk",
"manufacturer": "VMware",
"spindle_speed": 0,
"device_id": "1",
"indication_enabled": null
},
"sector_size": 512,
"partition_style": "RAW",
"number": 1,
"clustered": false,
"path": "\\\\?\\scsi#disk&ven_vmware&prod_virtual_disk#000100#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}",
"firmware_version": "1.0 ",
"guid": null,
"manufacturer": "VMware ",
"read_only": false,
"partition_count": 0,
"bootable": false,
"operational_status": "Online",
"friendly_name": "VMware Virtual disk",
"location": "SCSI3",
"serial_number": "6000c29d4858c95ebed8358d5573436a",
"model": "Virtual disk ",
"system_disk": false,
"unique_id": "6000C29D4858C95EBED8358D5573436A"
},
{
"size": 35433480192,
"bus_type": "SAS",
"physical_disk": {
"bus_type": "SAS",
"operational_status": "OK",
"partial": false,
"media_type": "SSD",
"supported_usages": {
"Count": 5,
"value": [
"Auto-Select",
"Manual-Select",
"Hot Spare",
"Retired",
"Journal"
]
},
"usage_type": "Auto-Select",
"firmware_version": "1.0",
"size": 35433480192,
"can_pool": true,
"allocated_size": 2097152,
"friendly_name": "VMware Virtual disk",
"object_id": "{1}\\\\\\root/Microsoft/Windows/Storage/Providers_v2\\SPACES_PhysicalDisk.ObjectId=\"{c8327f0b-13eb-11e7-a93d-806e6f6e6963}:PD:{1b1435ac-7bc0-f76f-9b75-1748149cada6}\"",
"health_status": "Healthy",
"unique_id": "6000C294F3C0C0A25FBA0DCEB5A68723",
"physical_location": "SCSI2",
"serial_number": "6000c294f3c0c0a25fba0dceb5a68723",
"model": "Virtual disk",
"manufacturer": "VMware",
"spindle_speed": 0,
"device_id": "3",
"indication_enabled": null
},
"sector_size": 512,
"partition_style": "RAW",
"number": 3,
"clustered": false,
"path": "\\\\?\\scsi#disk&ven_vmware&prod_virtual_disk#5&165ad43&0&000100#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}",
"firmware_version": "1.0 ",
"guid": null,
"manufacturer": "VMware ",
"read_only": true,
"partition_count": 0,
"bootable": false,
"operational_status": "Offline",
"friendly_name": "VMware Virtual disk",
"location": "SCSI2",
"serial_number": "6000c294f3c0c0a25fba0dceb5a68723",
"model": "Virtual disk ",
"system_disk": false,
"unique_id": "6000C294F3C0C0A25FBA0DCEB5A68723"
},
{
"size": 5368709120,
"bus_type": "SAS",
"physical_disk": {
"bus_type": "SAS",
"operational_status": "OK",
"partial": false,
"media_type": "SSD",
"supported_usages": {
"Count": 5,
"value": [
"Auto-Select",
"Manual-Select",
"Hot Spare",
"Retired",
"Journal"
]
},
"usage_type": "Auto-Select",
"firmware_version": "1.0",
"size": 5368709120,
"can_pool": true,
"allocated_size": 2097152,
"friendly_name": "VMware Virtual disk",
"object_id": "{1}\\\\\\root/Microsoft/Windows/Storage/Providers_v2\\SPACES_PhysicalDisk.ObjectId=\"{c8327f0b-13eb-11e7-a93d-806e6f6e6963}:PD:{a5fada66-6d0e-6736-1859-95c840f3e41b}\"",
"health_status": "Healthy",
"unique_id": "6000C2938D10730857A2EA01CCA777D1",
"physical_location": "SCSI1",
"serial_number": "6000c2938d10730857a2ea01cca777d1",
"model": "Virtual disk",
"manufacturer": "VMware",
"spindle_speed": 0,
"device_id": "2",
"indication_enabled": null
},
"sector_size": 512,
"partition_style": "RAW",
"number": 2,
"clustered": false,
"path": "\\\\?\\scsi#disk&ven_vmware&prod_virtual_disk#5&9b451b&0&000100#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}",
"firmware_version": "1.0 ",
"guid": null,
"manufacturer": "VMware ",
"read_only": false,
"partition_count": 0,
"bootable": false,
"operational_status": "Online",
"friendly_name": "VMware Virtual disk",
"location": "SCSI1",
"serial_number": "6000c2938d10730857a2ea01cca777d1",
"model": "Virtual disk ",
"system_disk": false,
"unique_id": "6000C2938D10730857A2EA01CCA777D1"
}
]
},
"_ansible_no_log": false
}
My ansible playbook:
---
#(still working) parse the data returned to match the uuid with disk number
- name: Gather disk facts from VMWare guest
vmware_guest_disk_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ username }}"
password: "{{ password }}"
datacenter: "{{ vcenter_datacenter }}"
validate_certs: no
name: "{{ vm_name }}"
delegate_to: localhost
register: vmware_disk_info
- name: Gather Windows disk facts
win_disk_facts:
- name: loop os disk output physical disk
debug:
msg: "{{ item.physical_disk.serial_number }}"
loop: "{{ ansible_facts.disks | list }}"
loop_control:
label: "{{ item.physical_disk.serial_number }}"
- name: loop vmware disk information backing_uuid
debug:
msg: "{{ vmware_disk_info.guest_disk_info[item|quote].backing_uuid }}"
loop: "{{ vmware_disk_info.guest_disk_info.keys() | list }}"
- name: set P drive (vmware disk 2:1)
set_fact:
p_disk_number: "{{ item.1.number }}"
loop: "{{ vmware_disk_info.guest_disk_info.keys() | product(ansible_facts.disks) | list }}"
loop_control:
label: "{{ item.1.physical_disk.serial_number }}"
when:
- item.1.physical_disk.serial_number is match(vmware_disk_info.guest_disk_info[item.0|quote].backing_uuid)
- name: p debug
debug: var=p_disk_number
#- name: loop vmware disk information capacity_in_bytes
# debug:
# msg: "{{ item.0.capacity_in_bytes }}"
# loop: "{{ vmware_disk_info | list }}"
# loop_control:
# label: "{{ item.0.capacity_in_bytes }}"
#- name: loop vmware disk information controller_bus_number
# debug:
# msg: "{{ item.controller_bus_number }}"
# loop: "{{ vmware_disk_info | list }}"
# loop_control:
# label: "{{ item.controller_bus_number }}"
#- name: loop vmware disk information unit_number
# debug:
# msg: "{{ item.unit_number }}"
# loop: "{{ vmware_disk_info | list }}"
# loop_control:
# label: "{{ item.unit_number }}"
#- name: loop os disk output physical disk
# debug:
# msg: "{{ item.physical_disk.serial_number }}"
# loop: "{{ ansible_facts.disks | list }}"
# loop_control:
# label: "{{ item.physical_disk.serial_number }}"
#- name: loop os disk output number
# debug:
# msg: "{{ item.number }}"
# loop: "{{ ansible_facts.disks | list }}"
# loop_control:
# label: "{{ item.number }}"
#- name: loop os disk output
# debug:
# msg: "{{ item.size }}"
# loop: "{{ ansible_facts.disks | list }}"
# loop_control:
# label: "{{ item.size }}"