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

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 close merge delete

Sort by » oldest newest most voted

Hello DarylW

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

more

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!

( 2017-02-23 07:59:46 -0600 )edit

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'

more