Puppet Resources Ordering

167 views
Skip to first unread message

chengkai liang

unread,
Sep 15, 2013, 1:14:17 AM9/15/13
to puppet...@googlegroups.com
Hi All,

   I have the following classes define:

   init.pp

      class { 'A': } ->
      class { 'B': } ->
      class { 'C': }

Supposedly, the execution order should A then B then C, but the actual execution order seems that C is being executed before B.  Why is this happening?  Isn't -> will chain up the resources order?

Anybody has any idea?

Thanks,
Chengkai

Rahul Khengare

unread,
Sep 16, 2013, 1:19:50 AM9/16/13
to puppet...@googlegroups.com
Hi Chengkai,
    I have faced similar kind of problem for class ordering using ordering arrow (->). You can try the stage resources for ordering classes.

Refer following code snippet,

#Declare stage resources
stage {'first':}
stage {'second':}
stage {'third':}

#Define ordering of stages
Stage[first] -> Stage[second] -> Stage[third]

#use stages in each classes.
class {'A':
       stage => first,
 }
class {'B':
       stage => second,
}
class {'C':
        stage => third,

Refer http://docs.puppetlabs.com/puppet/2.7/reference/lang_run_stages.html for stage resource for classes. 

Thanks and Regards,

Rahul Khengare,

NTT DATA OSS Center, Pune, India.

JuanBrein

unread,
Sep 16, 2013, 8:55:48 AM9/16/13
to puppet...@googlegroups.com
This could be related to a bug in puppet, even though  the dependency is defined between classes, the resources within the classes float and get executed in a different order. Take a look at the "anchor" pattern in the puppetlabs documentation.

Juan

jcbollinger

unread,
Sep 16, 2013, 9:43:18 AM9/16/13
to puppet...@googlegroups.com


On Monday, September 16, 2013 12:19:50 AM UTC-5, Rahul Khengare wrote:
Hi Chengkai,
    I have faced similar kind of problem for class ordering using ordering arrow (->). You can try the stage resources for ordering classes.



Run stages are indeed a mechanism for controlling application order of classes, but they are an awfully big and blunt hammer.  Indiscriminate use of stages is likely to get you into trouble.  Instead, you should fix the problem with your classes.

 

On Sunday, September 15, 2013 10:44:17 AM UTC+5:30, chengkai liang wrote:

Hi All,

   I have the following classes define:

   init.pp

      class { 'A': } ->
      class { 'B': } ->
      class { 'C': }

Supposedly, the execution order should A then B then C, but the actual execution order seems that C is being executed before B.  Why is this happening?  Isn't -> will chain up the resources order?



Chances are that the chain operator works fine, but your expectation of what it means to apply (not execute) a class is flawed.  Problems of this kind are usually containment issues: when one class declares another, that does not inherently place any ordering relationship between the declared and declaring classes, nor are relationships between the declaring class and any resources or other classes directly relevant to the declared class.  This is quite different from the case of actual resources declared by a given class.  The distinction is intentional and necessary, but that's a separate topic.

As JuanBrein suggested, you can find more information about the issue and the most common solution, the "anchor" pattern, in the language docs.  Here's a link: http://docs.puppetlabs.com/puppet/3/reference/lang_containment.html .


John

chengkai liang

unread,
Sep 16, 2013, 11:11:30 AM9/16/13
to puppet...@googlegroups.com
Thanks for this information.  I'm now looking at the anchor pattern.

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/OvTTmJm5QvA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages