我在 Puppet 中声明了以下资源define
。有一些参数以auth_*
该控制身份验证开头。我希望能够根据布尔变量 ie 的值传递该参数块,或者不传递它们$use_authentication
。
似乎一个if
语句在这里不起作用,我认为“选择器”也不会这样做。Felix Frank 在非常密切相关的问题“在 puppet 中定义条件”中有一个非常有用的答案,但我认为该策略不会在这里起作用,因为需要省略的参数嵌套了两层深。
apache::vhost { "$name-non-ssl":
servername => $vhost_name,
docroot => $document_root,
port => 80,
access_log_file => 'access.log',
access_log_format => 'vhost_common',
error_log_file => 'error.log',
directories => [
{path => $document_root,
auth_type => 'Basic',
auth_name => "$name",
auth_user_file => '/somefile.pwd',
auth_require => 'valid-user',
rewrites => [
{
comment => "rule1",
rewrite_base => "/",
rewrite_rule => ['^index\.html$ - [L]']
},
{
comment => "rule2",
rewrite_cond => ['%{REQUEST_FILENAME} !-f', '%{REQUEST_FILENAME} !-d'],
rewrite_rule => ['. /index.html [L]']
}
]}
],
}
以下给出了语法错误:Syntax error at 'if'; expected '}'
apache::vhost { "$name-non-ssl":
... same as previous ...
directories => [
{path => $document_root,
if $use_authentication {
auth_type => 'Basic',
auth_name => "$name",
auth_user_file => '/somefile.pwd',
auth_require => 'valid-user',
}
rewrites => [
...same as before...
]}
],
}