简体   繁体   English

木偶理解参数类

[英]puppet understanding parameters class

i am new in Puppet. 我是木偶新手。 I have a puppet basic infrastructure. 我有一个伪造的基本基础设施。 I installed from 我从安装

puppetforge "example42/lighttpd" puppetforge“ example42 / lighttpd”

I am able to deploy this class without a problem to a puppet controlled node. 我能够将此类毫无问题地部署到人偶控制的节点。 My problem now,.how can i use the parameters in this class? 我现在的问题是..如何在此类中使用参数? i am not understood where i can activate the parameters.i would like to deploy lighttpd with customized index.html and a different log file path.i hope u can give me a hind :) 我不知道我可以在哪里激活参数。我想使用自定义的index.html和不同的日志文件路径来部署lighttpd。我希望你能给我一个机会:)

In the file params.pp 在文件params.pp中

This class is not intended to be used directly.
It may be imported or inherited by other classes

but how can i imported this?? 但是我怎么导入呢?

First off, to get straight started with puppet, you should take a look at the documentation for the module in question (ie. README, README.md, etc.). 首先,要开始使用puppet,您应该查看所涉及模块的文档(即README,README.md等)。 Next, understand the params pattern. 接下来,了解params模式。 The params class in a puppet module is usually a class that contains NO resources, and is meant to hold default data for a module (data not supplied from outside sources like hiera). 人偶模块中的params类通常是不包含任何资源的类,用于保存模块的默认数据(数据不是从外部资源(例如hiera)提供的)。 most of the time you will see something like this: 大多数情况下,您会看到类似以下内容的信息:

inherits lighttpd::param

In the init, or another manifest file in a module. 在init或模块中的另一个清单文件中。 That is because it is inheriting the values from the params class. 那是因为它继承了params类的值。

Hope this helped at least a little bit. 希望这至少可以有所帮助。

In short, don't use params.pp directly (by declaring it). 简而言之,不要直接使用params.pp(通过声明)。 This class is part of params design pattern which states that default values for our parameters can be placed in params.pp puppet class which then can be inherited by all classes in which we need to access parameters that are defined in params.pp 此类是params设计模式的一部分,该模式指出可以将参数的默认值放在params.pp中。puppet类可以由所有需要访问在params.pp中定义的参数的类继承。

I think the best place to start is init.pp class which every Puppet module has. 我认为最好的起点是每个Puppet模块都有的init.pp类。 It can be found inside manifest directory in Puppet module you downloaded from Puppet Forge. 它可以在从Puppet Forge下载的Puppet模块的清单目录中找到。

/Users/bjusufbe/.puppetlabs/etc/code/modules/lighttpd/manifests
Bakirs-MacBook-Pro:manifests bjusufbe$ ls -la
total 56
drwxr-xr-x   6 bjusufbe  staff    204 Oct 23 19:27 .
drwxr-xr-x  10 bjusufbe  staff    340 Oct 23 19:27 ..
-rw-r--r--   1 bjusufbe  staff   1705 Oct 23 19:26 dotconf.pp
-rw-r--r--   1 bjusufbe  staff  15763 Oct 23 19:27 init.pp
-rw-r--r--   1 bjusufbe  staff   2633 Jul 17  2013 params.pp
-rw-r--r--   1 bjusufbe  staff    560 Apr 10  2013 spec.pp

If you open init.pp, you will see following class definition: 如果打开init.pp,将看到以下类定义:

class lighttpd (
  $use_ssl             = params_lookup( 'use_ssl' ),
  $my_class            = params_lookup( 'my_class' ),
  $source              = params_lookup( 'source' ),
  $source_dir          = params_lookup( 'source_dir' ),
  ...

All parameters use params_lookup custom function (not provided by Puppet but part of other modules from example42 namespace). 所有参数都使用params_lookup自定义函数(Puppet不提供,但是example42命名空间中其他模块的一部分)。 You can check details how this function is used on following link: How to use params_lookup in chapter: PARAMS LOOKUP ORDER 您可以在以下链接上查看有关如何使用此功能的详细信息:本章的“ 如何使用params_lookup ”:PARAMS LOOKUP ORDER

However, to make things easier for you, you can declare this class using following syntax in your site.pp (if you use Puppet master/agent scenario) or in any *.pp file in masterless scenario which can be applied simply by calling: 但是,为了使您更轻松,可以在site.pp(如果使用Puppet主/代理方案)中或在无主方案的任何* .pp文件中使用以下语法声明此类,只需调用以下方法即可应用:

puppet apply <name_of_pp_file>.pp

Simple declaration goes like this: 简单的声明如下:

class { 'lighttpd':
  <anyparameterfromthisclassdefinition> => <value>
}

Example: 例:

class { 'lighttpd':
  use_ssl => true,
}

If you don't want to pass any parameter in class declaration, then default values will be used that are calculated by custom function params_lookup for each parameter in this class. 如果您不想在类声明中传递任何参数,则将使用由自定义函数params_lookup为该类中的每个参数计算的默认值。 In that case, you could simply do this: 在这种情况下,您可以简单地执行以下操作:

include lighttpd

Hope this gives you enough to start. 希望这能给您足够的起点。 Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM