I am trying to write an Ansible playbook which will identify newly added disks on a RHEL machine. The plan is to run the playbook and cache the disks at that point in time as a fact prior to creating the new disks. After creating the new disks, the the same playbook would be run again and would compute the difference in disks before and after the disks are created.
For example, lsblk
initially returns the following:
NAME SIZE TYPE
sda 100G disk
├─sda1 1G part
└─sda2 99G part
├─rhel-root 50G lvm
├─rhel-swap 7.9G lvm
└─rhel-home 41.1G lvm
sr0 1024M rom
after adding 8 new disks, lsblk
returns:
NAME SIZE TYPE
sda 100G disk
├─sda1 1G part
└─sda2 99G part
├─rhel-root 50G lvm
├─rhel-swap 7.9G lvm
└─rhel-home 41.1G lvm
sdb 18.6G disk
sdc 18.6G disk
sdd 18.6G disk
sde 18.6G disk
sdf 18.6G disk
sdg 18.6G disk
sdh 18.6G disk
sdi 18.6G disk
sr0 1024M rom
Ideally I would be able to gather an initial list of disks of the form:
['sda']
and after creating the disks gather another list of disks of the form:
['sda', 'sdb', 'sdc', 'sdd', 'sde', 'sdf', 'sdg', 'sdh', 'sdi']
Computing the difference between the two lists would yield:
['sdb', 'sdc', 'sdd', 'sde', 'sdf', 'sdg', 'sdh', 'sdi']
which are the 8 newly created disks.
I am trying to avoid using a shell
or command
module call if possible.