On Sat, 18 Feb 2023 at 08:46, BILKAM <[email protected]> wrote:
>
> 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....
>
> {
>
> "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":[
>
> "Auto-Select",
> "Manual-Select",
> "Hot Spare",
> "Retired",
> "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 <[email protected]> wrote:
>>
>>
>>
>> On Fri, 17 Feb 2023 at 22:42, [email protected] <[email protected]>
>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/46639167-35f3-42cf-ad5a-2a14fcfd892bn%40googlegroups.com.
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAF8BbLZMxwQhBV%2BfybfXKWqiHp20Q%3DNdJGdXrqQVdRJ3ZjVU3A%40mail.gmail.com.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAHY7qGpDRA5%2B7bmz0yBUtWRNE9x6T9r1o7%3DiLhGMYh3FU%3D2a%3Dw%40mail.gmail.com.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAF8BbLYXMazpz116%2B6aox8EftqdS%2BsTWVo-caOf%3DV2iDbJxWWA%40mail.gmail.com.