博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
puppet自动化运维之cron资源
阅读量:6974 次
发布时间:2019-06-27

本文共 3612 字,大约阅读时间需要 12 分钟。

hot3.png

每一个cron资源需要一个command属性user属性以及至少一个周期属性(hour, minute, month, monthday, weekday)。

    计划任务的名字不是计划任务的一部分,它是puppet用来存储和检索该资源。假如你指定了一个除了名字其他的都和一个已经存在的计划任务相同,那么这两个计划任务被认为是等效的,并且新名字将会永久地与该计划任务相关联。一旦这种关联建立并写入磁盘之后,你就可以方便的进行计划任务的管理了。可以通过文件的方式来管理计划任务也可以通过计划任务格式来管理计划任务。

    随机数:

minute => inline_template("<%=   hostname.hash % 60   %>"),

hour => inline_template("<%=   (hostname+name).hash.abs % 24   %>"),

 

 时间参数:

  分    时    日     月      周       命令

minute hour month monthday weekday command

 

格式:

 

cron {"title":

    ensure => {present|absent}, #present不存在,则添加;absent存在,则删除

    command => "命令",      #欲执行的命令或脚本路径,也可不写,默认是title

    user => "用户",         #执行该cron的用户身份

    minute => "值",         #分,同crontab,不写,代表*

    hour => "值",           #时

    monthday =>   "值",       #日

    month => "值",          #月

    weekday => "值",        #周

}

 

 

除了用户和command两个参数以外,其他的参数都是可选项.

 

ensure      ensure => {present|absent},

决定该计划任务的目标状态,

present 如该cron不存在,则添加;

absent 如该cron已存在,则删除之

 

command     command => "命令",     

欲执行的命令或脚本路径,也可不写,默认是title

 

user        user => "用户",        

把该crontab加到那个用户的crontab列表,默认是运行puppet的用户。

 

minute      minute => "值",        

运行crontab的分钟,可设置成0-59,同crontab,不写,代表*。

 

hour        hour => "值",          

            运行crontab的小时,可设置成0-23。

 

monthday    monthday => "值",

            一个月份中的日子,1-31。

 

month       month => "值",

            设置crontab运行的月份,1-12。

 

weekda      weekday => "值",

            运行crontab的星期数,0-7,周日是为07。

 

    注:时间属性,不写,代表*;指定多个时间,使用数组,例:[1,3,5]。

 

实例:

#

vi /etc/puppet/manifest/test.pp

cron {"ntp time":

        ensure =>   present,

        command =>   "/sbin/ntpdate asia.pool.ntp.org",

        user =>   'root',

        minute => 0,

        hour =>   '6-13/3',

        month =>   [1,3,5,12];

}

 

#check

[root  ~]# crontab -l

0 * * * * /etc/webmin/bandwidth/rotate.pl

[root  ~]#

[root  ~]# puppet agent --test -vv --server   master.perofu.com

info: Caching catalog for client.perofu.com

info: Applying configuration version '1395082392'

notice: /Stage[main]//Cron[ntp time]/ensure:   created

notice: Finished catalog run in 0.13 seconds

[root  ~]# crontab -l

# HEADER: This file was autogenerated at Tue Mar 18 02:54:41   +0800 2014 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.

0 * * * * /etc/webmin/bandwidth/rotate.pl

# Puppet Name: ntp time

0 6-13/3 * 1,3,5,12 * /sbin/ntpdate asia.pool.ntp.org

 

#随机数

vi /etc/puppet/manifests/1.pp

 

cron {"run-puppet":

        command => "/usr/sbin/puppet agent --server=master.perofu.com --test >/dev/null  2>&1",

        minute => inline_template("<%= (hostname+name).hash.abs % 60 %>"),

#       #minute => inline_template("<%= hostname.hash.abs % 60 %>"),

}

 

#

[root  ~]# puppet agent --server=master.perofu.com --test

notice: Ignoring --listen on onetime run

Could not retrieve fact='arp_eth0', resolution='<anonymous>': undefined method `get_arp_value' for Facter::Util::IP:Module

Could not retrieve fact='arp_lo', resolution='<anonymous>': undefined method `get_arp_value' for Facter::Util::IP:Module

info: Caching catalog for client.perofu.com

info: Applying configuration version '1399358355'

notice: /Stage[main]//Cron[run-puppet]/ensure: created

notice: Finished catalog run in 0.28 seconds

[root  ~]#

[root  ~]#

[root  ~]# crontab -l

# HEADER: This file was autogenerated at Tue May 06 14:39:15 +0800 2014 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.

0 * * * * /etc/webmin/bandwidth/rotate.pl

# Puppet Name: run-puppet

49 * * * * /usr/sbin/puppet agent --server=master.perofu.com --test >/dev/null  2>&1

 

     至此,puppet的cron资源就结束了,接下来的是group资源的学习,请听下回分解!!!

转载于:https://my.oschina.net/fufangchun/blog/261174

你可能感兴趣的文章
Workman websocket 握手连接
查看>>
[洛谷P1901]发射站
查看>>
cordova封装h5为app,cookie不可用解决方法
查看>>
mysql limit 优化
查看>>
谈恋爱与形象
查看>>
day22 Pythonpython 本文xml模块
查看>>
Fisher's exact test( 费希尔精确检验)
查看>>
SSH项目里面 忘记密码的邮件发送功能
查看>>
对Linux(Unix)的基础知识归纳
查看>>
自定义可扩展叠加头部的下拉控件
查看>>
转--Java工程师成神之路(2018修订版)
查看>>
SQLServer之Compute/ComputeBy实现数据汇总
查看>>
KMP算法
查看>>
回车提交
查看>>
代码基本素质
查看>>
关于数据库的索引
查看>>
Apache POI使用详解(摘抄)
查看>>
PAT_A1076#Forwards on Weibo
查看>>
黑马程序员博客-------面向对象
查看>>
Python 类 面向对象(Classes)
查看>>