How to make sure the puppet class order works?

I am new to puppet deployment. I have two classes:

class taskname{ exec{ "deploy_script": command = "cp ${old_path} ${new path}", user = root, } cron{"cron_script2": command = "pyrhton ${new_path}", user = root, require = Exec["deploy_script"] } } class taksname2{ exec{ "deploy_script2": command = "cp ${old_path} ${new path}", user = root, } cron{"cron_script": command = "pyrhton ${new_path}", user = root, require = Exec["deploy_script2"] } } 

How can I be sure of the current order of these two classes. I tried in a new manifest file

init.pp to include these two classes

 include taskname include taskname2 

It seems that the second task is being performed before the first task. How to force an executable order?

+4
source share
2 answers

Use one of these metaparameters .

So, to summarize: whenever a resource depends on another resource, use before or require metaparameter or bind resources with -> . Whenever a resource needs to be updated when another resource changes, use the notify or subscribe notify or combine the resources with ~> . Some resources will automatically request other resources if they see them, which may save you a little effort.

Also works for classes declared with resource type syntax .

When declared using resource-like syntax, the class can use any metaparameter. In such cases, each resource contained in the class will also have this metaparameter. Therefore, if you declare a class with noop => true , each resource in the class will also have noop => true , unless they specifically override it. Metaparameters that can take more than one value (for example, metaparameters relations) will combine the values ​​from the container and any specific values ​​from an individual resource.

+5
source

Try using the metaparameter -> to indicate the dependency between the classes. In init.pp, where you declare / instantiate these classes, replace the include statements with the parameterized class syntax:

 class {"taskname":} -> class {"taskname2":} 

This ensures that taskname is called before taskname2 . For more information see http://docs.puppetlabs.com/guides/parameterized_classes.html#declaring-a-parameterized-class

+4
source

All Articles