Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet Execution Flow

Tags:

puppet

I have this node.pp and I am wondering how puppet is going to execute it.

node 'agent.puppet.demo' {
    include ssh
    include postfix
    include mysql
    include apache
}

On the agent node, when I run this:

$ puppetd -t -d

The puppet is not executing it sequentially meaning, it does not execute ssh first, then postfix, ...

Does anyone know why this is? Is it because it is called 'declarative language' where the order of execution does not really matter?

If this is the case, then I can just in a certain way, declare what I want and puppet will figure out how to execute it?

like image 316
Carmen Avatar asked Mar 01 '12 20:03

Carmen


2 Answers

Disclaimer: I am one of the developers of Puppet.

It will execute it in a consistent but unpredictable order, with the exception of any explicit or implicit dependencies in the code. Explicit dependencies are things that you specify with the subscribe or require metaparameters. Implicit dependencies come from the autorequire feature, which does things like automatically apply file resources in a sensible order.

The reason for this isn't so much that the language is declarative, but rather the language is declarative because order doesn't matter for most things in the underlying problem space.

For example, there really isn't much connection between managing ssh and managing postfix for most people - you could do the work in either order, or even at the same time, and everything would work out the same.

That frees us up to improve things in a whole lot of ways that "everything is in linear order" doesn't. We are working, for example, to batch up package installs while still respecting the explicit dependencies outside packages.

So, the order of execution and dependencies follows the underlying problem, and we have preserved that property to be able to do more awesome things.

The goal is exactly what you say at the end: that you declare what you want, and we take care of all the details of getting it there. In time we hope to be much smarter about logical dependencies, so you have to say even less to get that, too.

like image 194
Daniel Pittman Avatar answered Oct 03 '22 01:10

Daniel Pittman


Disclaimer: I am still pretty new to puppet :)

The key is to think of everything in terms of dependencies. For class dependencies, I like to use the Class['a'] -> Class['b'] syntax. Say you have a tomcat class that requires a jdk class which downloads/installs the sun jdk from oracle. In your tomcat class, you can specify this with

Class['jdk'] -> Class['tomcat']

Alternatively you can declare a class with a require meta parameter rather than using include.

like image 33
czervik Avatar answered Oct 03 '22 02:10

czervik