Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ruby复制自定义事实_Ruby_Puppet_Facter - Fatal编程技术网

使用ruby复制自定义事实

使用ruby复制自定义事实,ruby,puppet,facter,Ruby,Puppet,Facter,我是ruby新手,正在尝试让一个木偶自定义事实起作用。以下是自定义事实的代码: Facter.add("mounts") do confine :osfamily => "RedHat" setcode do mountlist="" #Facter::Core::Execution.exec('/bin/mount | /bin/cut -f3 -d" "') #mounts=`/bin/mount` mounts = Facter::Core::

我是ruby新手,正在尝试让一个木偶自定义事实起作用。以下是自定义事实的代码:

Facter.add("mounts") do
  confine :osfamily => "RedHat"
  setcode do
    mountlist=""
    #Facter::Core::Execution.exec('/bin/mount | /bin/cut -f3 -d" "')
    #mounts=`/bin/mount`
    mounts = Facter::Core::Execution.exec('/bin/mount')

    mounts.each_line do |line|
      fs=line.match(/^[^\s]+\s+on\s(.+) type.+/).captures
      mountlist=mountlist + fs.to_s + ","
    end
    mountlist
  end
end
代码的思想是创建一个名为
挂载的自定义事实,然后可以在模块的清单中使用它。以下是清单文件中的一节:

if ("/tmp" in $mounts) {
  mount{'tmpfs_mnt':
    name     => "/tmp",
    options  => [ 'nodev','nosuid','noexec' ],
    ensure   => present,
    atboot   => true,
    fstype   => tmpfs,
    remounts => true,
  }
}
自定义事实似乎未被创建。以下是尝试拉取此模块时其中一个傀儡节点的输出:

错误:无法从远程服务器检索目录:服务器上的错误400“in”表达式的右操作数中的“undef”不是受支持的类型(字符串、数组或哈希)


如果您能提供帮助,了解需要哪些更正才能使自定义事实生效,我们将不胜感激。

解决:自定义事实代码很好,问题出在代码的位置。一旦我将代码从~/lib/ruby/facter移动到~/lib/facter,它就工作了。实际上,您应该将事实放在
module/lib/facter/
中。解决:自定义事实代码很好,问题出在代码的位置。一旦我将代码从~/lib/ruby/facter移动到~/lib/facter,它就工作了。实际上,您应该将事实放在
module/lib/facter/
中。这将普遍有效。