Hi
Am having trouble to find unpartitioned drives through ansible.
I want all the unpartitioned drives put to a variable
example:
I have sda,sdb and sdc where sda is partitioned and sdb,sdc is left unpartitioned. I want the playbook to register both sub,sac to a variable
something like
“unpartitioned_drives”: {
“stdout_lines”: [
“/dev/sdb”,
“/dev/sdc”
Currently am doing this with shell which I want to do with ansible
- name: Finding Unpartiotioned drives
shell: for i in /dev/sd[b-z];do /sbin/partprobe -d -s $i | grep -v 1 | cut -d’:’ -f1;done
register: unpartitioned_drives - debug: var=unpartitioned_drives
I tried doing this but all am getting is last drive but not both with this code.
-
name: setfact
set_fact: unpartitioned_drives=“{{ item.key }}”
when: not item.value.partitions and item.key != “sr0” and item.key != “fd0”
with_dict: “{{ ansible_devices }}” -
debug: var=unpartitioned_drives
Output is
TASK [debug] ***********************************************************************************************************************************************************************************************
ok: [dal-appblx118-16.prod.walmart.com] => {
“changed”: false,
“unpartitioned_drives”: “sdc”
}
Since the last item is sdc it only stores sdc. Can anyone help to use this to store all unpartitioned drives in a single variable.