Ask Your Question
0

Difference between init.pp and site.pp and does each override other , in case of same setting mentioned in the two files?

asked 2017-02-21 23:51:39 -0500

Suresh300567 gravatar image

Hi Team , Am new to puppet , was working on BMC Bladelogic SA previously , can some one tell me the difference between init.pp and site.pp and does each override other , in case of same setting mentioned in the two files?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-02-22 23:12:23 -0500

Suresh300567 gravatar image

Hello DarylW

I understand it better than ever . Thanks for your detailed explanation .

edit flag offensive delete link more

Comments

If my answer was helpful for you, you can click on the checkmark on the left to accept the answer, which can help future people with the same problem find it. I'm glad it was helpful for you!

DarylW gravatar imageDarylW ( 2017-02-23 07:59:46 -0500 )edit
0

answered 2017-02-22 11:22:07 -0500

DarylW gravatar image

init.pp is the 'main' class for a module. site.pp is where you define site specific configuration/properties. There is a little bit of discussion about it in this hiera_example..

based on node definition documentation You would declare your node definitions inside of your site.pp

Basically you would have a site.pp where you define any global overrides, or in the example above, a hiera_enc by loading classes directly from hiera.

The value that gets loaded (from your ENC, hiera, or your node references) is what calls other modules, which will go through their init.pp. For example

If you have a module defined like this

#modules/foo/manifests/init.pp
class foo {
  file {'/tmp/message':
    content => 'Hello World',
}

and you have a node entry in your site.pp like this

# site.pp
node default {
  include 'foo'
}

Any node (since it didn't match a specific node, it resolves to the default node), will invoke the 'foo' class/module without any parameters, in this case it will create a file in /tmp/message with the contents 'Hello World'.

If you have a class with parameters, you can pass them in using the 'resource' style definition of a class.

#modules/bar/manifests/init.pp
class bar (
  $message = 'Hello World',
) {
  file {'/tmp/bar_message':
    content => $message,
}

and you have a node entry in your site.pp like this

# site.pp
node default {
  class { 'bar': 
    message => 'Called from site.pp',
  }
}

You will then have a file in /tmp/bar_message with the contents matching the passed in parameter, 'Called form site.pp'

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-02-21 23:51:39 -0500

Seen: 61 times

Last updated: Feb 22