How to check physical disk in puppet

puppetpuppetmaster

I have below linux script

cre_disk=$(ls /dev/sd[b-z])
for disk in $cre_isk
do 
pvcreate $i
done

My understanding from the above code is, it is checking the sdb,sdc..sdz disk file. if it exist, then do physical volume creation.

what my requirement is, need to convert the above linux into puppet(lvm creation). I know the command for physical volume creation

physical volume{'/dev/sdb':
ensure => 'present'
}

I am not sure how to check the physical disk (cre_disk=$(ls /dev/sd[b-z])). is there any resource available or puppet would take care without any resource.

NOTE:I have posted this same question in different format in previous question post. Please ignore the topic, the topic name is "check physical disk directory"

Best Answer

Facter's variable partitions:

[vagrant@localhost ~]$ facter partitions
{"sda1"=>{"uuid"=>"X", "size"=>"1024000", "mount"=>"/boot"}, "sda2"=>{"size"=>"Y"}}

could be used within an if statement as follows:

if $partitions !~ /sd[b-z]1/ {
  notify{"partition does not exist":}
}

Outcome

[vagrant@localhost ~]$ sudo puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for localhost.local
Info: Applying configuration version 'X'
Notice: drive does not exist
Notice: /Stage[main]/Main/Node[default]/Notify[partition does not exist]/message: defined 'message' as 'drive does not exist'
Notice: Finished catalog run in 0.07 seconds
Related Topic