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

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
主站蜘蛛池模板: 临漳县| 景东| 孟连| 芒康县| 林周县| 临汾市| 通山县| 台北市| 临颍县| 伊宁县| 丰镇市| 长宁区| 宁蒗| 武义县| 营山县| 多伦县| 修水县| 安阳市| 永兴县| 岳池县| 闽清县| 新安县| 衡山县| 金门县| 闽清县| 奈曼旗| 托里县| 沅陵县| 夏津县| 阳高县| 穆棱市| 张家界市| 张家界市| 汉沽区| 六盘水市| 历史| 夏河县| 上高县| 高雄县| 石屏县| 建阳市|