Ansible - delete all partitions on a given list of disks
Register to single variable info.
- parted:
device=/dev/{{ item }}
unit=MiB
register: info
loop: "{{ disks }}"
Use subelements to iterate the disks and partitions. For example
- hosts: localhost
vars:
disks:
- sda
- sdc
tasks:
- parted:
device: "/dev/{{ item }}"
unit: MiB
register: info
loop: "{{ disks }}"
- debug:
msg: "{{ item.0.disk.dev }} {{ item.1.num }}"
loop: "{{ info.results|subelements('partitions') }}"
gives
"msg": "/dev/sda 1"
"msg": "/dev/sda 2"
"msg": "/dev/sda 3"
"msg": "/dev/sda 5"
"msg": "/dev/sdc 1"