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
> <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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAF8BbLZMxwQhBV%2BfybfXKWqiHp20Q%3DNdJGdXrqQVdRJ3ZjVU3A%40mail.gmail.com.