運維利器puppet:管理crond任務

 利用puppet管理cron任務計劃:

   #vim /etc/puppet/manifests/modules.pp
Import "cron"                             #導入modules下的cron模塊
  #mkdir -p /etc/puppet/modules/cron/manifests
  #mkdir -p /etc/puppet/manifests/nodes/
  #cd /etc/puppet/manifests/nodes && vim node_1_1 
Node node.leju.com {                             #定義節點,包含哪些類
Include general
Include cron
}
  #vim  /etc/puppet/manifests/site.pp        #讓服務能掃描到配置.
Import "modules.pp"
Import "nodes/*.pp"
Import "base/*.pp" 
  #cd /etc/puppet/modules/cron/manifests/
   # vim base.pp                       #定義基本配置
       class cron::base {
                package { "vixie-cron":
                        name => $operatingsystem ? {
                                ubuntu => "cron",
                                redhat => "vixie-cron",
                                centos => "vixie-cron",
                                },
                        ensure => present,
                        }
                service { "crond":
                        name => $operatingsystem ? {
                                ubuntu => "crond",
                                redhat => "crond",
                                centos => "crond",
                                },
                        ensure => running,
                        enable => true,
                        pattern => cron,
                        require => Package["vixie-cron"],
                        }
}
  #Vim crontabs.pp                    #定義crontabs 包
      class cron::crontabs {
                package { "crontabs":
                        name => $operatingsystem ? {
                                ubuntu => "crontabs",
                                centos => "crontabs",
                                redhat => "crontabs",
                        },
                        ensure => present,
                        }
}
  #vim addcron.pp                       #定義任務計劃
     class cron::addcron {
                cron { "ntpdate":
                        command => "/usr/sbin/ntpdate ntp.sina.com.cn",
                        user => root,
                        hour => "*/1",
                        minute => "1";
                       "echo":
                        command => "/bin/echo \"hello,sina.com\"",
                        user => root,
                #       hour => "*/2",
                        minute => "1",
                        month => "*/1",
  }
}
# vim init.pp #定義初始化文件
   class cron {
                case $operatingsystem {
                        centos:{
                                include cron::base
                                include cron::crontabs
                                include cron::addcron
                                }
                        redhat:{
                                include cron::base
                                include cron::crontabs
                                include cron::addcron
                                }
                        ubuntu:{}
 }
}
服務端執行 puppetrun --host node.leju.com
或在客戶端執行 puppetd --test --debug
#crontab -l     ###可以看到任務計劃已經推送.
# HEADER: This file was autogenerated at Tue Aug 30 16:28:28 -0400 2011 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: echo
1 * * */1 * /bin/echo "hello,sina.com"
# Puppet Name: ntpdate
1 */1 * * * /usr/sbin/ntpdate ntp.sina.com.cn
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章