避免手动添加主机
class::define { [ 'host1.domain', 'host2.domain' ]: attribute => 'hello', attribute2 => 'world' } class::define { [ 'host3.domaintwo', 'host4.domaintwo' ]: attribute => 'apple', attribute2 => 'orange' }
通过使用导出的资源:
if $fqdn =~ /^.*\.domain$/ { @@class::define { $fqdn: attribute => 'hello', attribute2 => 'world', tag => 'test' } } if $fqdn =~ /^.*\.domaintwo$/ { @@class::define { $fqdn: attribute => 'apple', attribute2 => 'orange', tag => 'test2' } } Class::define <<| tag == 'test' and tag == 'test2' |>>
按预期工作。
题
if语句可以省略以获得相同的结果吗?
通过使出口无条件,您将引发冲突,因为清单现在声明导出的资源
Class::Define[$fqdn]
两次(具有不同的属性)。
您可以通过允许将FQDN作为属性值来传递,而不是期望它成为资源标题。
@@class::other_define { "hello-$fqdn": fqdn => $fqdn, attribute => 'hello', attribute2 => 'world', tag => 'test'; "fruit-$fqdn": fqdn => $fqdn, attribute => 'apple', attribute2 => 'orange', tag => 'test2'; }
只要确保仍在资源标题中使用 fqdn事实,以便不同代理的导出不会发生冲突。
顺便说一下,我不知道为什么select不同的标签,以及为什么只导入具有两个标签的资源“按预期”工作。 事实上,我希望不要input任何内容。