# Looping through win\_disk\_facts to detect drives and init them

**URL:** <https://forum.ansible.com/t/looping-through-win-disk-facts-to-detect-drives-and-init-them/35018>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [April 20, 2021, 2:51pm UTC](https://forum.ansible.com/t/looping-through-win-disk-facts-to-detect-drives-and-init-them/35018 "2021-04-20T14:51:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_J1](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@A\_J1](https://forum.ansible.com/u/A_J1)\
**Post date:** [April 20, 2021, 2:51pm UTC](https://forum.ansible.com/t/looping-through-win-disk-facts-to-detect-drives-and-init-them/35018/1 "2021-04-20T14:51:56Z")

</div>

I am trying to come up with a task that will step through the drives it finds from win\_disk\_facts and init them. This is my attempt so far. Any help would be appreciated.

- name: Get disk facts  
community.windows.win\_disk\_facts:

- name: Print out disks!  
community.windows.win\_initialize\_disk:  
loop: “{{ ansible\_facts.disks }}”  
loop\_control:  
loop\_var: disk.number

- AJ

---

<div class="post-metadata">

**Author:** ![A\_J1](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@A\_J1](https://forum.ansible.com/u/A_J1)\
**Post date:** [April 20, 2021, 4:01pm UTC](https://forum.ansible.com/t/looping-through-win-disk-facts-to-detect-drives-and-init-them/35018/2 "2021-04-20T16:01:13Z")

</div>

It looks like this works!

- name: Get disk facts  
community.windows.win\_disk\_facts:

- name: Print out disks!  
community.windows.win\_initialize\_disk:  
disk\_number: “{{ disk.number }}”  
loop: “{{ ansible\_facts.disks }}”  
loop\_control:  
loop\_var: disk  
when: ansible\_disks[disk\_number].guid is none

However, the output seems to be a large block of unused values. Is there a way to clean that up?

- AJ
