# Get the number of the disk offline

**URL:** <https://forum.ansible.com/t/get-the-number-of-the-disk-offline/37671>\
**Category:** Ansible Project\
**Created:** [February 17, 2023, 9:42pm UTC](https://forum.ansible.com/t/get-the-number-of-the-disk-offline/37671 "2023-02-17T21:42:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bilkam](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@bilkam](https://forum.ansible.com/u/bilkam)\
**Post date:** [February 17, 2023, 9:42pm UTC](https://forum.ansible.com/t/get-the-number-of-the-disk-offline/37671/1 "2023-02-17T21:42:26Z")

</div>

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}}”

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [February 17, 2023, 11:09pm UTC](https://forum.ansible.com/t/get-the-number-of-the-disk-offline/37671/2 "2023-02-17T23:09:31Z")

</div>

> 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](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.

---

<div class="post-metadata">

**Author:** ![bilkam](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@bilkam](https://forum.ansible.com/u/bilkam)\
**Post date:** [February 18, 2023, 7:45am UTC](https://forum.ansible.com/t/get-the-number-of-the-disk-offline/37671/3 "2023-02-18T07:45:42Z")

</div>

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](https://forum.ansible.com/uploads/short-url/81DEWc8qnnCIm9SjCW8AMvq696J.docx) (14.2 KB)

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [February 18, 2023, 2:37pm UTC](https://forum.ansible.com/t/get-the-number-of-the-disk-offline/37671/4 "2023-02-18T14:37:16Z")

</div>

> 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....
