官术网_书友最值得收藏!

  • Puppet 2.7 Cookbook
  • John Arundel
  • 284字
  • 2021-04-02 18:19:57

Running Puppet from cron

Is your Puppet sleeping on the job? By default, when you run the Puppet agent on a client, it will become a daemon (background process), waking up every 30 minutes to check for any manifest updates and apply them (optionally after a randomized delay using the splay setting in puppet.conf). If you want more control over when Puppet runs, you can trigger it using cron instead.

For example, if you have many Puppet clients, you may want to deliberately stagger the Puppet run times to spread the load on the Puppetmaster. A simple way to do this is to set the minute or hour of the cron job time using a hash of the client hostname.

How to do it...

Use Puppet's inline_template function, which allows you to execute Ruby code:

cron { "run-puppet":
    command => "/usr/sbin/puppet agent --test",
    minute  => inline_template("<%= hostname.hash.abs % 60 %>"),
}

service { "puppet":
    ensure => stopped,
    enable => false,
}

How it works...

Because each hostname produces a unique hash value, each client will run Puppet at a different minute past the hour. This hashing technique is useful for randomizing any cron jobs to improve the odds that they won't interfere with each other.

There's more...

You may find that running Puppet as a daemon leaks memory over time, or that occasionally Puppet can get into a stuck state when communicating with the master. Running Puppet from cron should also fix these problems.

There are other ways to trigger Puppet runs, including the MCollective tool, which we'll cover in detail elsewhere in this book.

See also

  • Efficiently distributing cron jobs section in Chapter 6
  • Using embedded Ruby section in Chapter 3
  • Using MCollective section in Chapter 9
主站蜘蛛池模板: 托克逊县| 遂平县| 南安市| 夏河县| 甘德县| 田林县| 宁蒗| 高碑店市| 长垣县| 昆明市| 集安市| 桐城市| 花垣县| 黎平县| 台中市| 霍林郭勒市| 广汉市| 罗甸县| 八宿县| 杭锦后旗| 龙口市| 全椒县| 五河县| 溧水县| 昌乐县| 南江县| 丁青县| 新蔡县| 云安县| 临邑县| 双柏县| 锡林浩特市| 和平县| 鲜城| 聊城市| 临泉县| 鄂尔多斯市| 抚远县| 南靖县| 郴州市| 平原县|