Ask Your Question
1

include class vs execute Class

asked 2013-06-28 15:23:04 -0500

BaltoStar gravatar image

updated 2013-06-28 18:56:43 -0500

I am wondering about differences between and pros/cons of the following two approaches to applying classes to a node :

node node1{
  include 'class1'
  include 'class2'
}

node node2{
  class{'class1'}
  class{'class2'}
  Class['class1'] -> Class['class2']
}

My understanding is that Class[] -> Class[] forces the classes to be applied in a specific order. So for node2, we have ensured that Puppet will apply class1 before class2.

But I'm sketchy on exactly what Class[] does ...

And what about when just using include ( for node1 ) ? Is an execution order ensured ?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
5

answered 2013-06-30 20:01:40 -0500

Ancillas gravatar image

updated 2013-06-30 20:05:26 -0500

Here's how I explain it to new Puppet users. If you add a class to the catalog using include, you can not pass in parameters. This limits the flexibility of the class unless you're using a tool like hiera within the class. However, it provides the flexibility of being able to call a class as many times you want throughout your code. You could write include apt a hundred times, and Puppet would never care because if apt had already been included in the catalog, it would just use the already existing copy.

Conversely, calling a class like ... (more)

edit flag offensive delete link more
1

answered 2013-06-29 04:44:58 -0500

You have to use class{'class1':} when using parameterized Classes.

include does not support parameters.

With include you have no execution order. Include just loads the code and executes it somewhere in some order.

edit flag offensive delete link more
0

answered 2013-06-28 15:51:33 -0500

In Puppet, first one is called include-like and second way is called resource-like. You can read more about it here. I don't think there is any order implied in both cases unless you specify that explicitly or class internal structure causes some dependencies in the catalogue that dictates the order.

edit flag offensive delete link more
0

answered 2013-06-28 15:54:08 -0500

updated 2013-06-28 19:30:42 -0500

It's all about consistency and what feels more natural for your team, but there is an article on best practices :

class : include versus resources

Hope that helps.

EDIT : Not sure what would be the purpose of Class['class1'] -> Class['class2']

But you can achieve the same with (the valid, note the ':' ) :

  class{'class1':}
   ->
  class{'class2':}
edit flag offensive delete link more

Comments

Strange that docs on resource-like behavior discuss the class{} directive but not the Class[] directive. My understanding is that to ensure that classes are applied in a certain order you ...(more)

BaltoStar gravatar imageBaltoStar ( 2013-06-28 18:46:28 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-06-28 15:23:04 -0500

Seen: 3,750 times

Last updated: Jun 30 '13