1

我正在尝试(mountpoint => "/")使用 Puppet 因子获取根分区名称。当我运行时"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 == '/' }你们有什么想法吗?

4

1 回答 1

2

您可以通过哈希表示法直接访问此事实。由于您的问题严重暗示您正在使用 Facter 3/Puppet 4,因此我将使用该语法。

您只需直接遍历 Facter 散列中的键即可得出该/dev/md3值。如果我们将散列最小化到相关部分facter mountpoints

{
  / => {
    device => "/dev/md3"
  }
}

然后我们看到密钥是mountpoints(当您facter mountpoints从 CLI 访问该密钥时直接访问该密钥)/、 和device. 因此,在 Puppet 中使用带有$facts哈希的标准哈希表示法,我们可以通过以下方式访问该值:

$facts['mountpoints']['/']['device'] # /dev/md3

在此处查看更多信息:https ://docs.puppet.com/puppet/4.9/lang_facts_and_builtin_vars.html#the-factsfactname-hash

于 2017-02-25T16:39:44.183 回答