简体   繁体   中英

puppet understanding parameters class

i am new in Puppet. I have a puppet basic infrastructure. I installed from

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 :)

In the file 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.). Next, understand the params pattern. 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). most of the time you will see something like this:

inherits lighttpd::param

In the init, or another manifest file in a module. That is because it is inheriting the values from the params class.

Hope this helped at least a little bit.

In short, don't use params.pp directly (by declaring it). 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

I think the best place to start is init.pp class which every Puppet module has. It can be found inside manifest directory in Puppet module you downloaded from Puppet Forge.

/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:

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). You can check details how this function is used on following link: How to use params_lookup in chapter: 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:

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. In that case, you could simply do this:

include lighttpd

Hope this gives you enough to start. Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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