我有以下的Linux脚本
cre_disk=$(ls /dev/sd[bz]) for disk in $cre_isk do pvcreate $i done
从上面的代码我的理解是,它是检查sdb,sdc..sdz磁盘文件。 如果存在,那么做物理卷创build。
我的要求是什么,需要把上面的linux转换成puppet(lvm创build)。 我知道创build物理卷的命令
physical volume{'/dev/sdb': ensure => 'present' }
我不知道如何检查物理磁盘(cre_disk = $(ls / dev / sd [bz]))。 有没有资源可用或木偶会照顾没有任何资源。
注:我已经在以前的问题post中以不同的格式发布了相同的问题。 请忽略该话题,话题名称为“查看物理磁盘目录”
Facter的可变分区 :
[vagrant@localhost ~]$ facter partitions {"sda1"=>{"uuid"=>"X", "size"=>"1024000", "mount"=>"/boot"}, "sda2"=>{"size"=>"Y"}}
可以在if语句中使用 ,如下所示:
if $partitions !~ /sd[bz]1/ { notify{"partition does not exist":} }
结果
[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
你有多个选项。
让puppet在目标机器上运行脚本是完全可能的。 根据脚本的作用,你想阻止它多次运行。 这将是这样的情况。
您可以在目标计算机上添加facter模块,以将事件的块设备信息导出。 https://github.com/CygnusNetworks/cygnus-puppet-disk-facter就是这样一个模块。