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