Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Absolute puppet beginner here. I'm experiencing an interesting behavior with my puppet manifests and would love to know what I'm doing wrong. Let's for example say I'm configuring the instance with the following ordered classes:

class { 'update_system': } ->
class { 'facter': } ->
class { 'user_sshkey': user => 'ubuntu', type => 'rsa', } ->
class { 'tmux': user => 'ubuntu', } ->
class { 'vim': user => 'ubuntu', } ->
class { 'bashrc': user => 'ubuntu' } ->
notify {"Configuring DB role":} ->
class { 'postgresql': }

when I run the manifest with the --debug switch, by looking at notify statements I can see the classes be executed in the following order:

1. update_system starts
2. a cron type inside of postgresql class (the very **last** class in that ordered list above) is executed
3. postgres::install starts
5. facter starts installing
6. postgres::configure and postgres::service start
7. the vim class is executed
8. "Configuring DB role" notification is made. All the way at the end here.
etc

Basically the thing is all over the place, the order doesn't seem to follow the arrow operators in any way.

I'm guessing I'm missing something here that would force the classes to execute one at a time. Could it be that I'm missing some kind of anchor pattern here? Invalid containment?

Edit: as far as I can tell is that part of the issue is that I used nested classes inside of postgres module along the lines of:

class postgres {
   class{'postgres::install': } ->
   class{'postgres::config': } ~>
   class{'postgres::service': } ->
}

and it's my understanding that this won't work too well without the anchor hack, as per bug 8040

Am I getting this correctly?

share|improve this question
    
i know this is not going to help you right now, but you're doing it wrong! When i started with puppet i had lots of situations like this, but in hindsight now i know it was usually because i was going about the problem entirely wrongly. -- in this case, you seem to have an awful lot of order based logic where there need not be any. I'd advise starting with learning how modules work and interact (or more importantly don't interact). Don't forget puppet is meant to be idempotent. –  Sirex Jul 3 '13 at 3:46
    
Very possible, I do suspect that's causing the issue. Do you have specific suggestions for what is going wrong here? –  Alexandr Kurilin Jul 3 '13 at 3:50
    
oh, and see if you can get a copy of "pro puppet" it's not perfect, but it's a really good headstart. –  Sirex Jul 3 '13 at 3:50
    
Well, to put it anouther way; I think our puppet code base is around 5000 lines now, and the number of times we've needed class{} -> class{} is currently zero. –  Sirex Jul 3 '13 at 3:53
    
Interesting, what are you currently using to indicate dependency between applications? I was partially following this article and it makes consistent use of -> and ~> at least on the sub-class level. And yes, some of those classes listed above do not have to be in that particular order. Some do. –  Alexandr Kurilin Jul 3 '13 at 3:56

2 Answers 2

up vote 5 down vote accepted

You're creating a dependency with a class (postgresql) and the resources directly declared within it. This doesn't create a dependency with classes that are included from there (postgresql::install). So, the resources from postgresql::install are not involved in the dependency structure you're creating at all.

What you need is for the resources to just depend on what they really require, instead of trying to enforce a high-level order - if you need to have the system update done before a specific resource runs, then just require it from there.

share|improve this answer
    
I don't agree with this. The way he is doing it is just fine, and clear to understand. Use the Anchor pattern and don't turn your puppet modules into spaghetti. –  robbyt Jul 3 '13 at 14:13
2  
@robbyt Let me clarify my statement. If the classes truly depend on each other, then I agree with chaining them (and using the anchor pattern to do it). But in the example in the question, the classes appear to be mostly unrelated; it doesn't look like there needs to be ordering at all except for maybe a couple relationships. When it seems that the ordering is more of "this is the order I would do them in manually" (which can be hard for new users to let go of) instead of "this needs to happen before that or that will break", I don't think the complexity of the anchor pattern is warranted. –  Shane Madden Jul 3 '13 at 15:43

When you order your classes like this, you would think that explicit ordering would apply to the resources inside the classes also, but they don't...

There is a long outstanding bug in Puppet that requires you "anchor" resources inside classes to their parent class. http://projects.puppetlabs.com/issues/8040

This bug has a workaround, but it's a bit hard to understand: http://projects.puppetlabs.com/projects/puppet/wiki/Anchor_Pattern

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.