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",
               2. "Manual-Select",
               3. "Hot Spare",
               4. "Retired",
               5. "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

On Sat, Feb 18, 2023 at 12:09 AM Dick Visser <dnmvis...@gmail.com> wrote:

>
>
> On Fri, 17 Feb 2023 at 22:42, bilel....@gmail.com <bilel.kamm...@gmail.com>
> wrote:
>
>> 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.
>
>
>     - 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}}"
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to ansible-project+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/46639167-35f3-42cf-ad5a-2a14fcfd892bn%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/46639167-35f3-42cf-ad5a-2a14fcfd892bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> Sent from Gmail Mobile
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLZMxwQhBV%2BfybfXKWqiHp20Q%3DNdJGdXrqQVdRJ3ZjVU3A%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAF8BbLZMxwQhBV%2BfybfXKWqiHp20Q%3DNdJGdXrqQVdRJ3ZjVU3A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAHY7qGpDRA5%2B7bmz0yBUtWRNE9x6T9r1o7%3DiLhGMYh3FU%3D2a%3Dw%40mail.gmail.com.

Attachment: ALL DISK INFORMATIONS.docx
Description: MS-Word 2007 document

Reply via email to