如何在Puppet

时间:2015-09-30 03:32:19

标签: vagrant puppet vagrant-provision

我有这个木偶课

class project::className(
  $program_name = '',
  $command = ''
) {
   ....
}

我正在使用它

class { 'project::classname':
  program_name => 'programe_name',
  command => 'ls /dev/'
}

这种方法很好,但是当我像这样使用它两次时

class { 'project::classname':
  program_name => 'programe_name',
  command => 'ls /dev/'
}

class { 'project::classname':
  program_name => 'programe_name2',
  command => 'ls /dev/'
}

Vagrant Provision给了我这个错误

错误:重复声明:类[project :: classname]已在文件中声明..

所以我的问题是如何重用该课程?

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要了解类和已定义类型的区别。

Classes Vs Defined Types

Classes are not to be thought of in the ‘object oriented’ meaning of a class. This means a machine belongs to a particular class of machine.

For instance, a generic webserver would be a class. You would include that class as part of any node that needed to be built as a generic webserver. That class would drop in whatever packages, etc, it needed to do.

Defined types on the other hand (created with ‘define’) can have many instances on a machine, and can encapsulate classes and other resources. They can be created using user supplied variables. For instance, to manage iptables, a defined type may wrap each rule in the iptables file, and the iptables configuration could be built out of fragments generated by those defined types.

Usage of classes and defined types, in addition to the built-in managed types, is very helpful towards having a managable Puppet infrastructure.

参考:https://docs.puppetlabs.com/guides/best_practices.html