Get the number of the disk offline

Hello,

I need to get the number for the disk offline.

My playbook is look like the below but I stuck with the json query and I need you help

Thanks

tasks:

  • name: Get disk facts
    win_disk_facts:
    delegate_to: “{{inventory_hostname}}”
    register: win_disk_facts

  • name: Set the query to get the related part of the win_disk_facts
    set_fact:
    query: “ansible_facts.ansible_disks[*].?operational_status==Offline”

  • name: Get the index number of the disk letter in the disk info
    set_fact:
    index : “{{ loop_index }}”
    loop: “{{ win_disk_facts | json_query(query) }}”
    loop_control:
    index_var: loop_index
    loop_var: inner_item
    when: inner_item | length > 0

  • name: Set the backing_uuid
    set_stats:
    data:
    number: “{{ win_disk_facts.ansible_facts.ansible_disks[index].number}}”

Hello,

I need to get the number for the disk offline.

My playbook is look like the below but I stuck with the json query and I need you help

And we need better input from you.
For example what the win_disk_facts variable looks like, for a start.
Some additional tips below inline

Thanks

tasks:

  • name: Get disk facts
    win_disk_facts:
    delegate_to: “{{inventory_hostname}}”

This seems like a redundant entry, by default tasks are run on the target. You can skip that line.

register: win_disk_facts

According to the docs at
https://docs.ansible.com/ansible/latest/collections/community/windows/win_disk_facts_module.html#returned-facts:

Facts returned by this module are added/updated in the hostvars host facts and can be referenced by name just like any other host fact. They do not need to be registered in order to use them.

So you can skip the register statement as well.

Hello, thank you for your support.
I’m sorry if I wasn’t clear enough
What I’m trying to do is make a playbook to initiate disk on a windows server.
The first step is to get all information on all the disks and parse the json for offline disks only.
The json for all disks looks like the attached file, and what I like to get with json query is only this based on (“operational_status”:“Offline”).

  1. {
    • “clustered”:false,
    • “friendly_name”:“VMware Virtual disk”,
    • “number”:2,
    • “sector_size”:512,
    • “partition_count”:0,
    • “unique_id”:“6000C29A05421A969E0AF41B32CEF539”,
    • “manufacturer”:"VMware ",
    • “system_disk”:false,
    • “operational_status”:“Offline”,
    • “firmware_version”:"2.0 ",
    • “guid”:null,
    • “model”:"Virtual disk ",
    • “size”:10737418240,
    • “read_only”:true,
    • “bus_type”:“SAS”,
    • “bootable”:false,
    • “partition_style”:“RAW”,
    • “physical_disk”:{
      • “manufacturer”:“VMware”,
      • “operational_status”:“OK”,
      • “firmware_version”:“2.0”,
      • “size”:10737418240,
      • “partial”:false,
      • “object_id”:“{1}\\Z32-DV-I1-WIN05\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{71eb514a-8ce5-11ed-8722-806e6f6e6963}:PD:{30478b6d-6b77-59cd-ef21-cb1e9d733a62}"”,
      • “usage_type”:“Auto-Select”,
      • “media_type”:“HDD”,
      • “friendly_name”:“VMware Virtual disk”,
      • “supported_usages”:{
        - “value”:[
        1. “Auto-Select”,
        1. “Manual-Select”,
        1. “Hot Spare”,
        1. “Retired”,
        1. “Journal”],
        - “Count”:5},
      • “bus_type”:“SAS”,
      • “device_id”:“2”,
      • “can_pool”:true,
      • “indication_enabled”:null,
      • “unique_id”:“6000C29A05421A969E0AF41B32CEF539”,
      • “serial_number”:“6000c29a05421a969e0af41b32cef539”,
      • “allocated_size”:2097152,
      • “spindle_speed”:“Unknown”,
      • “model”:“Virtual disk”,
      • “physical_location”:“SCSI0”,
      • “health_status”:“Healthy”},
    • “serial_number”:“6000c29a05421a969e0af41b32cef539”,
    • “location”:“SCSI0”,
    • “path”:“\\?\scsi#disk&ven_vmware&prod_virtual_disk#5&1ec51bf7&0&000200#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}”}

This allows me to get the disk number to initiate the disk on the windows server.

Regards

(attachments)

ALL DISK INFORMATIONS.docx (14.2 KB)

Hello, thank you for your support.
I'm sorry if I wasn't clear enough
What I'm trying to do is make a playbook to initiate disk on a windows server.
The first step is to get all information on all the disks and parse the json for offline disks only.
The json for all disks looks like the attached file, and what I like to get with json query is only this based on ("operational_status":"Offline").

I'm not too familiar with the data structure as you posted, but it
looks like there is just one vmware virtual disk (operational status:
offline), which has one physical disk (operational status: OK).
Since you mentioned "disks" (i.e. plural), I would expect a list data
structure - not a single dictionary with a single dict inside it....