避免木偶清单重复

我有一组configuration文件需要部署到每个服务器上的多个位置,每个服务器都有不同的内容,但是他们都共享相同的位置结构。 我正在尝试通过创build一个可以多次使用的公共类来减less我在清单中的复制量。

这是一个简单的文件结构的例子:

/home/bob/config/files.cfg /home/bob/config/settings.cfg /home/sue/config/files.cfg /home/sue/config/settings.cfg /home/ann/config/files.cfg /home/ann/config/settings.cfg 

这是我写的清单。

 class config-generic { file { "/home/$name/config/files.cfg": owner => $name, group => $name, source => "puppet://puppet.domain.com/files/home/$name/config/files.cfg", mode => 644, } file { "/home/$name/config/settings.cfg": owner => $name, group => $name, source => "puppet://puppet.domain.com/files/home/$name/config/settings.cfg", mode => 644, } } 

在类的第一次使用它工作正常。

 node "client1", "client2" { class {'config-generic': name => 'bob', } } 

但是当我再次使用这个类的时候,因为这个类已经定义了,所以错误。

SERVER上的错误400:重复定义:Class [config-generic]已被定义

 node "client1", "client2" { class {'config-generic': name => 'bob', } class {'config-generic': name => 'sue', } } 

问题:我理解这个问题 – 但是,在我的清单中减less复制的更好方法是什么? 我试图避免必须为每个文件的每个用户定义一个“ 文件 ”条目。

你需要的不是一个类,而是一个定义,因为你想要创build它们的几个实例,如:

 define config-generic ($ensure=present) { file { "/home/$name/config/files.cfg": ensure => $ensure, owner => $name, group => $name, source => "puppet://puppet.domain.com/files/home/$name/config/files.cfg", mode => '0644', } file { "/home/$name/config/settings.cfg": ensure => $ensure, owner => $name, group => $name, source => "puppet://puppet.domain.com/files/home/$name/config/settings.cfg", mode => '0644', } } 

并用以下方式调用它:

 node "client1", "client2" { config-generic { 'bob':; 'sue':; } } 

如果只有很小的差异,您可能还想使用模板,而不是复制源文件。