我需要一个方法来传递给定的variables – 可以说thearch – 给一个给定的类中的几个不同的文件。 我需要能够为每个文件单独陈述这个variables的内容。
我已经尝试了以下内容:
file { "xxx": thearch => "i386", path => "/xxx/yyyy", owner => root, group => root, mode => 644, content => template("module/test.erb"), }
这不会传递这个variables,所以我可以像我期望的那样在erb文件中使用<%= thearch%>语句。
我在这里做错了什么?
您需要将文件包装在一个定义中,该定义使用该参数,以便在调用模板时可用,然后调用该定义。 如果很多参数通常都是相同的,那么只要保持代码清洁,就将它们设置为默认值。
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"; }
您不能像“thearch”那样为文件资源定义任意的元参数。 唯一可用的元参数是这里的。 你可以使用现有的架构的事实,从节点可能会给你你想要的function。
<%= architecture %>
也许
<% if architecture == 'i386' then -%> do some stuff <% end-%>
你不能这样做。 对资源的参数不是任意值。 不过你可以这样做:
thearch = "i386" file { "xxx": path => "/xxx/yyyy", owner => root, group => root, mode => 644, content => template("module/test.erb"), }