puppet自動化之資源定義大收尾

exec命令管控資源



[root@centos7 ~]# cat exec.pp   執(zhí)行密等的命令
exec{'mktemp':
    command => 'mktemp -d /tmp/dir.XXX',
    path => '/bin:/sbin:/usr/bin:/usr/sbin',
}
[root@centos7 ~]# cat exec.pp 
exec{'mktemp':
    command => 'mktemp -d /tmp/dir.XXX',
    path => '/bin:/sbin:/usr/bin:/usr/sbin',
}
exec{'mkdir':
    command => 'mkdir /tmp/mydir',
    path => '/bin:/sbin:/usr/bin:/usr/sbin',
#   create => '/tmp/mydir',
    unless => 'test -d /tmp/mydir',  條件是執(zhí)行命令
}
[root@centos7 ~]# puppet apply -v exec.pp 第一次執(zhí)行兩個資源都執(zhí)行
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.04 s
econdsInfo: Applying configuration version '1506281057'
Notice: /Stage[main]/Main/Exec[mktemp]/returns: executed successfully兩個都執(zhí)行
Notice: /Stage[main]/Main/Exec[mkdir]/returns: executed successfully
Notice: Finished catalog run in 0.08 seconds
[root@centos7 ~]# puppet apply -v exec.pp  第二次執(zhí)行
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.04 seconds
Info: Applying configuration version '1506281512'
Notice: /Stage[main]/Main/Exec[mktemp]/returns: executed successfully
Notice: Finished catalog run in 0.08 seconds

cron 計劃任務資源定義

Installs and manages cron jobs.  Every cron resource created by Puppet requires a command and at least one periodic attribute (hour, minute, month, monthday, weekday, or special).
            
            command:要執(zhí)行的任務;
            ensure:present/absent;
            hour:
            minute:
            monthday:
            month:
            weekday:
            user:以哪個用戶的身份運行命令
            target:添加為哪個用戶的任務
            name:cron job的名稱;
            
            示例:
[root@centos7 ~]# vim  ch.pp 
                cron{'timesync':
                    command => '/usr/sbin/ntpdate 172.16.0.1 &> /dev/null',
                    ensure  => present,
                    minute  => '*/3',
                    user    => 'root',
                }           
[root@centos7 ~]# puppet apply -v --noop ch.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.07 seconds
Info: Applying configuration version '1506282122'
Notice: /Stage[main]/Main/Cron[timesync]/ensure: current_value absent, should be present (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.17 seconds
[root@centos7 ~]# puppet apply -v ch.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.05 seconds
Info: Applying configuration version '1506282266'
Notice: /Stage[main]/Main/Cron[timesync]/ensure: created
Notice: Finished catalog run in 0.08 seconds

[root@centos7 ~]# crontab -l
# HEADER: This file was autogenerated at 2017-09-25 03:44:27 +0800 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: timesync
*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &> /dev/null
[root@centos7 ~]# cat ch.pp 
cron{'timesync':
                    command => '/usr/sbin/ntpdate 172.16.0.1 &> /dev/null',
                    ensure  => absent,  刪除計劃任務的定義
                    minute  => '*/3',
                    user    => 'root',
                }

[root@centos7 ~]# puppet apply -v ch.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.05 s
econdsInfo: Applying configuration version '1506253646'
Notice: /Stage[main]/Main/Cron[timesync]/ensure: removed
Notice: Finished catalog run in 0.08 seconds



最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末是整,一起剝皮案震驚了整個濱河市祠挫,隨后出現(xiàn)的幾起案子走芋,更是在濱河造成了極大的恐慌纳账,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件狼犯,死亡現(xiàn)場離奇詭異余寥,居然都是意外死亡,警方通過查閱死者的電腦和手機悯森,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門宋舷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人瓢姻,你說我怎么就攤上這事祝蝠。” “怎么了幻碱?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵绎狭,是天一觀的道長。 經(jīng)常有香客問我褥傍,道長儡嘶,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任恍风,我火速辦了婚禮蹦狂,結果婚禮上,老公的妹妹穿的比我還像新娘邻耕。我一直安慰自己鸥咖,他們只是感情好,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布兄世。 她就那樣靜靜地躺著啼辣,像睡著了一般。 火紅的嫁衣襯著肌膚如雪御滩。 梳的紋絲不亂的頭發(fā)上鸥拧,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天,我揣著相機與錄音削解,去河邊找鬼富弦。 笑死,一個胖子當著我的面吹牛氛驮,可吹牛的內(nèi)容都是我干的腕柜。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼矫废,長吁一口氣:“原來是場噩夢啊……” “哼盏缤!你這毒婦竟也來了?” 一聲冷哼從身側響起蓖扑,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤唉铜,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后律杠,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體潭流,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡竞惋,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了灰嫉。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片拆宛。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖熬甫,靈堂內(nèi)的尸體忽然破棺而出胰挑,到底是詐尸還是另有隱情,我是刑警寧澤椿肩,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布瞻颂,位于F島的核電站,受9級特大地震影響郑象,放射性物質(zhì)發(fā)生泄漏贡这。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一厂榛、第九天 我趴在偏房一處隱蔽的房頂上張望盖矫。 院中可真熱鬧,春花似錦击奶、人聲如沸辈双。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽湃望。三九已至,卻和暖如春痰驱,著一層夾襖步出監(jiān)牢的瞬間证芭,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工担映, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留废士,地道東北人。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓蝇完,卻偏偏與公主長得像官硝,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子短蜕,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容

  • Ubuntu的發(fā)音 Ubuntu没龙,源于非洲祖魯人和科薩人的語言铺厨,發(fā)作 oo-boon-too 的音缎玫。了解發(fā)音是有意...
    螢火蟲de夢閱讀 99,260評論 9 467
  • linux資料總章2.1 1.0寫的不好抱歉 但是2.0已經(jīng)改了很多 但是錯誤還是無法避免 以后資料會慢慢更新 大...
    數(shù)據(jù)革命閱讀 12,161評論 2 33
  • Puppet理論定義: Puppet 是一個跨平臺的集中化配置管理系統(tǒng),它使用自有的描述語言解滓,可管理配置文件赃磨、用戶...
    屬于你的世界閱讀 963評論 0 2
  • 純手工打造每一篇開源資訊與技術干貨,數(shù)十萬程序員和Linuxer已經(jīng)關注洼裤。 Cron 是UNIX中一個常見的工具邻辉,...
    塵世不擾閱讀 557評論 0 1
  • 前一天學習了 at 命令是針對僅運行一次的任務,循環(huán)運行的例行性計劃任務腮鞍,linux系統(tǒng)則是由 cron (cro...
    Zcclucky閱讀 577評論 0 0