puppet自動(dòng)化之資源定義大收尾

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í)行兩個(gè)資源都執(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兩個(gè)都執(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 計(jì)劃任務(wù)資源定義

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í)行的任務(wù);
            ensure:present/absent;
            hour:
            minute:
            monthday:
            month:
            weekday:
            user:以哪個(gè)用戶的身份運(yùn)行命令
            target:添加為哪個(gè)用戶的任務(wù)
            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,  刪除計(jì)劃任務(wù)的定義
                    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



最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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