人偶 3.8.x 变量无法应用于模板
puppet 3.8.x variable can't apply to template
module/bareos_backup_client/manifests/init.pp:
class bareos_backup_client {
@@file { "${fqdn}-bareos-client.conf":
mode => 600,
owner => bareos,
group => bareos,
path => "/etc/bareos/director.d/${fqdn}-client.conf",
content => template("bareos_backup_client/bareos-dir-cliententry.erb"),
tag => 'bareos-client',
notify => Service[bareos-dir],
}
}
module/bareos_backup_client/templates/bareos-dir-cliententry.erb:
<% if @clientrunbeforejob -%>
ClientRunBeforeJob = "<%= @clientrunbeforejob %>"
<% end -%>
<% if @clientrunafterjob -%>
ClientRunAfterJob = "<%= @clientrunafterjob %>"
<% end -%>
manifests/nodes/server_1.pp:
include bareos_backup_client
$clientrunbeforejob = "apple"
为什么clientrunbeforejob变量不能注入erb模板?
您尝试使用 dynamic scoping。这多年来一直没有奏效,这是有充分理由的!
您可能希望将此值作为 class parameter.
传递
class bareos_backup_client($clientrunbeforejob) {
...
}
然后像这样声明它
class { 'bareos_backup_client':
clientrunbeforejob => 'apple'
}
module/bareos_backup_client/manifests/init.pp:
class bareos_backup_client {
@@file { "${fqdn}-bareos-client.conf":
mode => 600,
owner => bareos,
group => bareos,
path => "/etc/bareos/director.d/${fqdn}-client.conf",
content => template("bareos_backup_client/bareos-dir-cliententry.erb"),
tag => 'bareos-client',
notify => Service[bareos-dir],
}
}
module/bareos_backup_client/templates/bareos-dir-cliententry.erb:
<% if @clientrunbeforejob -%>
ClientRunBeforeJob = "<%= @clientrunbeforejob %>"
<% end -%>
<% if @clientrunafterjob -%>
ClientRunAfterJob = "<%= @clientrunafterjob %>"
<% end -%>
manifests/nodes/server_1.pp:
include bareos_backup_client
$clientrunbeforejob = "apple"
为什么clientrunbeforejob变量不能注入erb模板?
您尝试使用 dynamic scoping。这多年来一直没有奏效,这是有充分理由的!
您可能希望将此值作为 class parameter.
传递class bareos_backup_client($clientrunbeforejob) {
...
}
然后像这样声明它
class { 'bareos_backup_client':
clientrunbeforejob => 'apple'
}