icn icn - 4 months ago 9
Ruby Question

How to make sure the running order of puppet classes?

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

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 do I make sure the running order of these two classes.
I have tried in a new manifest file

init.pp to include these two classes

include taskname
include taskname2


It seems that second task running before the first task. How to I enforce the running order?

Answer

Use one of these metaparameters.

So to sum up: whenever a resource depends on another resource, use the before or require metaparameter or chain the resources with ->. Whenever a resource needs to refresh when another resource changes, use the notify or subscribe metaparameter or chain the resources with ~>. Some resources will autorequire other resources if they see them, which can save you some effort.

Also works for classes declared with a resource-like syntax.

When declared with the resource-like syntax, a class may use any metaparameter. In such cases, every resource contained in the class will also have that metaparameter. So if you declare a class with noop => true, every resource in the class will also have noop => true, unless they specifically override it. Metaparameters which can take more than one value (like the relationship metaparameters) will merge the values from the container and any specific values from the individual resource.