我正在尝试使用puppet facter获取一个根分区(mount => "/")
名称。当我运行" facter partitions
"时,它显示了三个分区。我想从结果中获取变量" sda3"。
{
/dev/sda1 => {
size => "1.00 MiB",
size_bytes => 1048576
},
/dev/sda2 => {
filesystem => "ext2",
mount => "/boot",
size => "477.00 MiB",
size_bytes => 500170752,
uuid => "8345d60e-e09a-4723-b5a6-149f4002706d"
},
/dev/sda3 => {
filesystem => "ext4",
mount => "/",
size => "49.71 GiB",
size_bytes => 53376712704,
uuid => "a1330fb2-7f13-417e-8908-813b1fdae911"
},
我尝试了$hddname = $facts['partitions']['mount'] == "/"
,但有错误。你们有任何想法吗?
处理哈希和阵列时,您可能想要木偶迭代和循环功能。该页面链接到一些有用的功能,并将帮助您找到所需的功能。
首先,您需要 filter 输入:
$root_partition = $facts['partitions'].filter |$device, $partition| { $partition['mount'] == '/' }
这将把整个/dev/sda3哈希分配给 $root_partition
,相当于 {"/dev/sda3" => {"filesystem" .... }}
。
然后使用stdlib的keys
函数从左侧的单个哈希键中提取设备名称:
$hddname = keys($root_partition)[0]