title: Ansible to check for unused disks of certain size and create a volume group
body: <p>I am pretty new to Ansible and a brand new member of Stackoverflow.</p>
  
  <p>I am trying to create a playbook that would look for unused disks (can be SAN, Solidfire, or localdisk). Filter them according to the size variable and create a volume group out of those disks that fall within the criteria.</p>
  
  <p>For example the server has 2x 50GB disk and 2x 100GB disk.</p>
  
  <p>I want it so that even if user enters <code>51Gb</code> size or <code>49 GB</code> size, the playbook should be able to take into account the +-5gb error margin. </p>
  
  <p>The part where I am stuck is how to filter unused disks by size with the +- 5gb error margin. </p>
  
  <p>I can look up the unused disks by </p>
  
  <pre><code>set fact:
    disks: "{{ansible_local.unused_disks}}"
  </code></pre>
  
  <p>this gives a list of unused disks. But how can I filter that list for specic size with error margin descried above ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Yup you are right. <code>ansible_local.unused_disks</code> does not exists. </p>
  
  <p>On the server I checked before it was put there using custom facts. Which will not be the case on every single server. Hence I will need to find another way to look up the disks. </p>
  
  <p>I checked with another SA and was given this code.</p>
  
  <pre><code> - name: Discover Disks
     set_fact:
       disks: "['/dev/{{item.key}}']"
     when:
       - not item.value.partitions
       - not item.value.holder
       - not item.value.links.ids
       - item.key | search ("sd")
     with_dict: "{{ ansible_devices }}"
  </code></pre>
  
  <p>But it is giving me an output that only shows the first unused device found instead of all unused device in a list. So I will need help with this too.</p>