Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 671
icn Avatar asked Jan 15 '23 15:01

icn


2 Answers

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.

like image 50
Mike Sherrill 'Cat Recall' Avatar answered Jan 19 '23 20:01

Mike Sherrill 'Cat Recall'


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

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

This will ensure taskname is invoked before taskname2. For more information, see http://docs.puppetlabs.com/guides/parameterized_classes.html#declaring-a-parameterized-class

like image 34
gabrtv Avatar answered Jan 19 '23 19:01

gabrtv