Puppet - 使用文件创建命令传递变量

Tim*_*ham 5 puppet

我需要一种方法来将给定的变量 - 比如说 thearch - 传递给给定类中的几个不同文件。我需要能够单独说明每个文件的这个变量的内容。

我尝试了以下方法:

file { "xxx":
  thearch => "i386",
  path    => "/xxx/yyyy",
  owner   => root,
  group   => root,
  mode    => 644,
  content => template("module/test.erb"),
}
Run Code Online (Sandbox Code Playgroud)

这不会传递这个变量,所以我可以像我期望的那样在 erb 文件中使用 <%=thearch%> 语句。

我在这里做错了什么?

fre*_*eit 5

您需要将文件包装在接受该参数的定义中,以便在调用模板时它可用,然后调用该定义。如果许多参数通常相同,请将它们设置为默认值,以保持代码整洁。

define thearch_file($thearch, $path, $owner = root, $group = root, $mode = 0644, $template = '/module/test.erb') {
  file { $name:
    path    => $path,
    owner   => $owner,
    group   => $group,
    mode    => $mode,
    content => template($template),
  }
}

thearch_file {
  "xxx":
    thearch => 'i386',
    path    => "/xxx/yyy";
  "yyy":
    thearch => 'x86_64',
    path    => "/xxx/zzz";
}
Run Code Online (Sandbox Code Playgroud)