Puppet:使用 factor 过滤器获取挂载点
Puppet : get mountpoint using facter filter
我正在尝试使用 Puppet facter 获取根分区 (mountpoint => "/")
名称。当我运行"facter mountpoints"
时,它显示多个分区。我想从结果中获取变量 "/dev/md3"
。
{
/ => {
available => "893.71 GiB",
available_bytes => 959608590336,
capacity => "1.86%",
device => "/dev/md3",
filesystem => "ext4",
options => [
"rw",
"errors=remount-ro"
],
size => "910.69 GiB",
size_bytes => 977843884032,
used => "16.98 GiB",
used_bytes => 18235293696
},
/run => {
available => "794.91 MiB",
available_bytes => 833527808,
capacity => "0.07%",
device => "tmpfs",
filesystem => "tmpfs",
options => [
"rw",
"noexec",
"nosuid",
"size=10%",
"mode=0755"
],
size => "795.48 MiB",
size_bytes => 834125824,
used => "584.00 KiB",
used_bytes => 598016
},
/tmp => {
available => "1.78 GiB",
available_bytes => 1909157888,
capacity => "1.21%",
device => "/dev/md1",
filesystem => "ext4",
options => [
"rw"
],
size => "1.80 GiB",
size_bytes => 1932533760,
used => "22.29 MiB",
used_bytes => 23375872
}
}
我尝试使用过滤器,但无法过滤 "/"
设备。
$root_mount = $facts['mountpoints'].filter |$mountpoint| { $mountpoint == '/' }
你们有什么想法吗?
您可以通过散列符号直接访问此事实。由于您的问题在很大程度上暗示您正在使用 Facter 3/Puppet 4,因此我将使用该语法。
直接遍历Facter hash中的key,得到/dev/md3
值。如果我们将散列最小化到 facter mountpoints
:
的相关部分
{
/ => {
device => "/dev/md3"
}
}
然后我们看到键是 mountpoints
(当您从 CLI 执行 facter mountpoints
时直接访问了该键)、/
和 device
。因此,在 Puppet 中使用带有 $facts
散列的标准散列符号,我们可以通过以下方式访问该值:
$facts['mountpoints']['/']['device'] # /dev/md3
点击这里了解更多信息:https://docs.puppet.com/puppet/4.9/lang_facts_and_builtin_vars.html#the-factsfactname-hash
我正在尝试使用 Puppet facter 获取根分区 (mountpoint => "/")
名称。当我运行"facter mountpoints"
时,它显示多个分区。我想从结果中获取变量 "/dev/md3"
。
{
/ => {
available => "893.71 GiB",
available_bytes => 959608590336,
capacity => "1.86%",
device => "/dev/md3",
filesystem => "ext4",
options => [
"rw",
"errors=remount-ro"
],
size => "910.69 GiB",
size_bytes => 977843884032,
used => "16.98 GiB",
used_bytes => 18235293696
},
/run => {
available => "794.91 MiB",
available_bytes => 833527808,
capacity => "0.07%",
device => "tmpfs",
filesystem => "tmpfs",
options => [
"rw",
"noexec",
"nosuid",
"size=10%",
"mode=0755"
],
size => "795.48 MiB",
size_bytes => 834125824,
used => "584.00 KiB",
used_bytes => 598016
},
/tmp => {
available => "1.78 GiB",
available_bytes => 1909157888,
capacity => "1.21%",
device => "/dev/md1",
filesystem => "ext4",
options => [
"rw"
],
size => "1.80 GiB",
size_bytes => 1932533760,
used => "22.29 MiB",
used_bytes => 23375872
}
}
我尝试使用过滤器,但无法过滤 "/"
设备。
$root_mount = $facts['mountpoints'].filter |$mountpoint| { $mountpoint == '/' }
你们有什么想法吗?
您可以通过散列符号直接访问此事实。由于您的问题在很大程度上暗示您正在使用 Facter 3/Puppet 4,因此我将使用该语法。
直接遍历Facter hash中的key,得到/dev/md3
值。如果我们将散列最小化到 facter mountpoints
:
{
/ => {
device => "/dev/md3"
}
}
然后我们看到键是 mountpoints
(当您从 CLI 执行 facter mountpoints
时直接访问了该键)、/
和 device
。因此,在 Puppet 中使用带有 $facts
散列的标准散列符号,我们可以通过以下方式访问该值:
$facts['mountpoints']['/']['device'] # /dev/md3
点击这里了解更多信息:https://docs.puppet.com/puppet/4.9/lang_facts_and_builtin_vars.html#the-factsfactname-hash