5

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?

Carmen
  • 2,833
  • 4
  • 23
  • 23

2 Answers2

17

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.

Daniel Pittman
  • 16,733
  • 4
  • 41
  • 34
  • 2
    Can you please define what is *consistent but unpredictable order*? We are having many issues when Puppet 2.6 just re-orders steps and due to some missing dependencies it fails. This is untesteable. Can I force some kind of shuffle so we can test it properly? I've also heard new version gives it fixed order. – lzap Sep 18 '12 at 15:25
  • So, say, for instance I have a package to install that depends on the existing of a repository in yum.repos.d. How can I enforce having the repository installed before it tries to install the package? – Mojo Feb 06 '14 at 22:46
3

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.

czervik
  • 2,537
  • 23
  • 15
  • So, I guess i have to add the following lines to make sure the dependencies get applied correctly. Class['apache'] -> Class['mysql'] -> Class['postfix'] -> Class['ssh'] Is there another approach to accomplish a sequential order without making the independent modules interdependent using internal Require=> Class ... – Maverick Oct 10 '12 at 18:05
  • You have that backwards. Class['a'] -> Class['b'] means Class b requires Class a. The way I like to do it is, each package in it's own module. Each module specifies it's own dependencies on other classes. I like to use a base uber class for stuff like ssh that is required by everything. For that I use run stages to ensure it always runs first. – czervik Oct 10 '12 at 21:16
  • @czervik do you mind to show how you include your uber class for stuff like ssh so that it is included by every other class? – memyself Apr 02 '14 at 20:10