puppet自動(dòng)化之file

file文件資源的定義

file:
                    Manages files, including their content, ownership, and permissions.
                    
                    ensure:Whether the file should exist, and if so what kind of file it should be. Possible values are `present`, `absent`, `file`, `directory`, and `link`.
                        file:類型為普通文件庄涡,其內(nèi)容由content屬性生成或復(fù)制由source屬性指向的文件路徑來(lái)創(chuàng)建;
                        link:類型為符號(hào)鏈接文件,必須由target屬性指明其鏈接的目標(biāo)文件漂羊;
                        directory:類型為目錄强霎,可通過(guò)source指向的路徑復(fù)制生成杨名,recurse屬性指明是否遞歸復(fù)制抚吠;
                    path:文件路徑冀痕;
                    source:源文件福铅;
                    content:文件內(nèi)容萝毛;
                    target:符號(hào)鏈接的目標(biāo)文件; 
                    owner:屬主
                    group:屬組
                    mode:權(quán)限滑黔;
                    atime/ctime/mtime:時(shí)間戳笆包;
[root@centos7 ~]# cat file.pp  定義以個(gè)復(fù)制某文件到某目錄下的文件
file{'/etc/redis.conf':
    source => '/root/redis.conf',
    owner => redis,
    group => root,
    ensure => file,
}
[root@centos7 ~]# puppet apply -v --noop file.pp  干跑運(yùn)行檢查語(yǔ)法
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.13 seconds
Info: Applying configuration version '1506266600'
Notice: /Stage[main]/Main/File[/etc/redis.conf]/content: current_value {md5}d98629fded012cd2
a25b9db0599a9251, should be {md5}375f2bc6dfa3bdacfbcdd24b29d08daf (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.22 seconds
[root@centos7 ~]# puppet apply -v file.pp  運(yùn)行
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.12 seconds
Info: Applying configuration version '1506266783'
Info: /Stage[main]/Main/File[/etc/redis.conf]: Filebucketed /etc/redis.conf to puppet with sum d98629fd
ed012cd2a25b9db0599a9251Notice: /Stage[main]/Main/File[/etc/redis.conf]/content: content changed '{md5}d98629fded012cd2a25b9db0
599a9251' to '{md5}375f2bc6dfa3bdacfbcdd24b29d08daf'Notice: Finished catalog run in 0.15 seconds
通知元參數(shù):
                    A notify B:B依賴于A,接受由A觸發(fā)refresh略荡;
                    B subscribe A:B依賴于A庵佣,接受由A觸發(fā)refresh;
                    
                    示例1:
                        file{'test.txt':
                            path    => '/tmp/test.txt',
                            ensure  => file,
                            source  => '/etc/fstab',
                        }

                        file{'test.symlink':
                            path    => '/tmp/test.symlink',
                            ensure  => link,
                            target  => '/tmp/test.txt',
                            require => File['test.txt'],
                        }

                        file{'test.dir':
                            path    => '/tmp/test.dir',
                            ensure  => directory,
                            source  => '/etc/yum.repos.d/',
                            recurse => true,
                        }
[root@centos7 ~]# cat servicecx.pp 
service{'redis':
    ensure => true,
    enable => true,
    hasrestart => true,
#   subscribe => File ['/etc/redis.conf'], #表示下面資源發(fā)生會(huì)觸發(fā)此資源刷新
}
file{'/etc/redis.conf':
    source => '/root/redis.conf',
    owner => redis,
    group => root,
    ensure => file,
#   notify => Service['redis'],#表示此資源發(fā)生變化會(huì)通知給上面的資源
}
File['/etc/redis.conf'] ~> Service['redis'] #也是表示下面的資源發(fā)生變化通知上面的資源

root@centos7 ~]# puppet apply -v --noop servicecx.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.27 s
econdsInfo: Applying configuration version '1506267989'
Notice: /Stage[main]/Main/File[/etc/redis.conf]/content: current_value {md5}375f2b
c6dfa3bdacfbcdd24b29d08daf, should be {md5}87104f85cf87166e4215cdf7646f9103 (noop)Info: /Stage[main]/Main/File[/etc/redis.conf]: Scheduling refresh of Service[redis
]Notice: /Stage[main]/Main/Service[redis]: Would have triggered 'refresh' from 1 ev
entsNotice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.09 seconds
[root@centos7 ~]# ss -lnt   檢查結(jié)果
State      Recv-Q Send-Q                             Local Address:Port                                            Peer Address:Port              
LISTEN     0      128                               172.16.251.203:6379                                                       *:*                  
LISTEN     0      128                                            *:111                                                        *:*                  
LISTEN     0      5                                  192.168.122.1:53                                                         *:*                  
LISTEN     0      128                                            *:22                                                         *:*                  
LISTEN     0      128                                    127.0.0.1:631                                                        *:*                  
LISTEN     0      100                                    127.0.0.1:25                                                         *:*                  
LISTEN     0      128                                           :::111                                                       :::*                  
LISTEN     0      128                                           :::22                                                        :::*                  
LISTEN     0      128                                          ::1:631                                                       :::*                  
LISTEN     0      100                                          ::1:25                                                        :::*                  
[root@centos7 ~]# cat cfx.pp  創(chuàng)建一個(gè)自動(dòng)生成內(nèi)容的文件
file{'chenxi.txt':
    path => '/tmp/chenxi.txt',
    content => 'hi there\n',
    ensure => file,
}
[root@centos7 ~]# puppet apply -v --noop cfx.pp  干跑運(yùn)行檢查是否有錯(cuò)
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.11 s
econdsInfo: Applying configuration version '1506268825'
Notice: /Stage[main]/Main/File[chenxi.txt]/ensure: current_value absent, should be
 file (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.03 seconds
[root@centos7 ~]# puppet apply -v cfx.pp    生成此文件
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.13 s
econdsInfo: Applying configuration version '1506268853'
Notice: /Stage[main]/Main/File[chenxi.txt]/ensure: defined content as '{md5}d52a8a
0512f44317a61ee80d8b9eb784'Notice: Finished catalog run in 0.11 seconds
[root@centos7 ~]# cat /tmp/chenxi.txt 
hi there\n
復(fù)制目錄及目錄下的所有文件
[root@centos7 ~]# cat cfx.pp 
file{'chenxi.txt':
    path => '/tmp/chenxi.txt',
    content => 'hi there\n',
    ensure => file,
}
[root@centos7 ~]# puppet apply -v  fgcx.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.12 s
econdsInfo: Applying configuration version '1506269549'
Notice: /Stage[main]/Main/File[/tmp/pam.d]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/pam.d/runuser]/ensure: defined content as '{md
5}b8b44b045259525e0fae9e38fdb2aeeb'Notice: /Stage[main]/Main/File[/tmp/pam.d/system-auth]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/pam.d/smtp.postfix]/ensure: defined content as
 '{md5}a4fb464fbcf0f1f470ea2016d120df62'Notice: /Stage[main]/Main/File[/tmp/pam.d/passwd]/ensure: defined content as '{md5
}dcc4e27593a30780464a87d69edfcf68'Notice: /Stage[main]/Main/File[/tmp/pam.d/pluto]/ensure: defined content as '{md5}
f0188fc8f667dc97590f885fd1adfc7d'Notice: /Stage[main]/Main/File[/tmp/pam.d/remote]/ensure: defined content as '{md5
}5841e2efb8ead55ad7f0a385c41db2da'Notice: /Stage[main]/Main/File[/tmp/pam.d/polkit-1]/ensure: defined content as '{m
d5}038eb4e924b8027bfe852e63edb998de'Notice: /Stage[main]/Main/File[/tmp/pam.d/gdm-pin]/ensure: defined content as '{md
5}0545417c9f340889324a244afe9d137a'Notice: /Stage[main]/Main/File[/tmp/pam.d/password-auth]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/pam.d/cups]/ensure: defined content as '{md5}b
b713ba94821433dbf61113eaa532a31'Notice: /Stage[main]/Main/File[/tmp/pam.d/vlock]/ensure: defined content as '{md5}
7ddd3d661b917ab94d398a5d88033ed6'Notice: /Stage[main]/Main/File[/tmp/pam.d/gdm-password]/ensure: defined content as
 '{md5}6e95fcc3e9cc35473e475b6edf8e58f2'Notice: /Stage[main]/Main/File[/tmp/pam.d/su-l]/ensure: defined content as '{md5}7
56fef5687fecc0d986e5951427b0c4f'Notice: /Stage[main]/Main/File[/tmp/pam.d/fingerprint-auth-ac]/ensure: defined con
tent as '{md5}f47f343a190b3b5b88276570a33552cc'Notice: /Stage[main]/Main/File[/tmp/pam.d/gdm-launch-environment]/ensure: defined 
content as '{md5}3056e83ce16b77618f463eab6ecb83d6'Notice: /Stage[main]/Main/File[/tmp/pam.d/gdm-fingerprint]/ensure: defined content
 as '{md5}414790e978e9d5e688d213cbcf52d3e0'Notice: /Stage[main]/Main/File[/tmp/pam.d/sudo-i]/ensure: defined content as '{md5
}6151e51bcdcf427be3d57ca53cca02f7'Notice: /Stage[main]/Main/File[/tmp/pam.d/gdm-smartcard]/ensure: defined content a
s '{md5}30cb356eaf252adecebb60f14758e16e'Notice: /Stage[main]/Main/File[/tmp/pam.d/smartcard-auth]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/pam.d/vmtoolsd]/ensure: defined content as '{m
d5}5b4c1dd1b10c8b1b99d084146ff5cc60'Notice: /Stage[main]/Main/File[/tmp/pam.d/setup]/ensure: defined content as '{md5}
64ee33eed57429e249335b4c64c88ec9'Notice: /Stage[main]/Main/File[/tmp/pam.d/gdm-autologin]/ensure: defined content a
s '{md5}b9d28c0e446abbb36439200b6e6b24c6'Notice: /Stage[main]/Main/File[/tmp/pam.d/sudo]/ensure: defined content as '{md5}b
a24c05c27c14f376233910f656dfa66'Notice: /Stage[main]/Main/File[/tmp/pam.d/runuser-l]/ensure: defined content as '{
md5}2106ea05877e8913f34b2c77fa02be45'Notice: /Stage[main]/Main/File[/tmp/pam.d/xserver]/ensure: defined content as '{md
5}3a78b7163c9f27314c0f8d3658f3813c'Notice: /Stage[main]/Main/File[/tmp/pam.d/other]/ensure: defined content as '{md5}
af140f3d3ae7fcf504f103e72256cfef'Notice: /Stage[main]/Main/File[/tmp/pam.d/sshd]/ensure: defined content as '{md5}c
a51dcdb22404ef8cfb875583388c9de'Notice: /Stage[main]/Main/File[/tmp/pam.d/password-auth-ac]/ensure: defined conten
t as '{md5}358c54c8ef7d1c16191fd015da90d3a6'Notice: /Stage[main]/Main/File[/tmp/pam.d/chfn]/ensure: defined content as '{md5}2
0697b6a640ccd785cb8c96ac8c1ff7c'Notice: /Stage[main]/Main/File[/tmp/pam.d/smtp]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/pam.d/postlogin]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/pam.d/config-util]/ensure: defined content as 
'{md5}ac222217925c4552d63a8982a1c2937c'Notice: /Stage[main]/Main/File[/tmp/pam.d/chsh]/ensure: defined content as '{md5}2
0697b6a640ccd785cb8c96ac8c1ff7c'Notice: /Stage[main]/Main/File[/tmp/pam.d/postlogin-ac]/ensure: defined content as
 '{md5}1af006491505807b0aff49584045cf2e'Notice: /Stage[main]/Main/File[/tmp/pam.d/atd]/ensure: defined content as '{md5}00
0d2f30379d2bf8af09f51416e863ec'Notice: /Stage[main]/Main/File[/tmp/pam.d/crond]/ensure: defined content as '{md5}
73dbc2487cc4d9f5fab5e4cdea7aed7e'Notice: /Stage[main]/Main/File[/tmp/pam.d/ppp]/ensure: defined content as '{md5}f6
21e5f4c67b70a30f446fa397b9c9be'Notice: /Stage[main]/Main/File[/tmp/pam.d/fingerprint-auth]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/pam.d/systemd-user]/ensure: defined content as
 '{md5}75f50eec5885dbbcc548d248c75bb194'Notice: /Stage[main]/Main/File[/tmp/pam.d/login]/ensure: defined content as '{md5}
0e8c66d8879a5f4c55b82e2fcc19459a'Notice: /Stage[main]/Main/File[/tmp/pam.d/system-auth-ac]/ensure: defined content 
as '{md5}4e1f3dce31807b69fed4ac37ecffeaad'Notice: /Stage[main]/Main/File[/tmp/pam.d/liveinst]/ensure: defined content as '{m
d5}f5be82be51135cf46de5955695f67c0d'Notice: /Stage[main]/Main/File[/tmp/pam.d/smartcard-auth-ac]/ensure: defined conte
nt as '{md5}0d667e4761f4e703e9b479d0f595b61f'Notice: /Stage[main]/Main/File[/tmp/pam.d/su]/ensure: defined content as '{md5}951
e804edc88857ad7fbce0fc515e23f'Notice: Finished catalog run in 0.59 seconds
[root@centos7 ~]# cat lik.pp 創(chuàng)建連接文件
file{'/tmp/tesr.link':
    ensure => link,
    target => '/tmp/chenxi.txt',
}




最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末汛兜,一起剝皮案震驚了整個(gè)濱河市巴粪,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌粥谬,老刑警劉巖肛根,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異漏策,居然都是意外死亡派哲,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門掺喻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)芭届,“玉大人,你說(shuō)我怎么就攤上這事巢寡『聿保” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵抑月,是天一觀的道長(zhǎng)树叽。 經(jīng)常有香客問(wèn)我,道長(zhǎng)谦絮,這世上最難降的妖魔是什么题诵? 我笑而不...
    開(kāi)封第一講書人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任洁仗,我火速辦了婚禮,結(jié)果婚禮上性锭,老公的妹妹穿的比我還像新娘赠潦。我一直安慰自己,他們只是感情好草冈,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布她奥。 她就那樣靜靜地躺著,像睡著了一般怎棱。 火紅的嫁衣襯著肌膚如雪哩俭。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 51,598評(píng)論 1 305
  • 那天拳恋,我揣著相機(jī)與錄音凡资,去河邊找鬼。 笑死谬运,一個(gè)胖子當(dāng)著我的面吹牛隙赁,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播梆暖,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼伞访,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了式廷?” 一聲冷哼從身側(cè)響起咐扭,我...
    開(kāi)封第一講書人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎滑废,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體袜爪,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蠕趁,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了辛馆。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片俺陋。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖昙篙,靈堂內(nèi)的尸體忽然破棺而出腊状,到底是詐尸還是另有隱情,我是刑警寧澤苔可,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布缴挖,位于F島的核電站,受9級(jí)特大地震影響焚辅,放射性物質(zhì)發(fā)生泄漏映屋。R本人自食惡果不足惜苟鸯,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望棚点。 院中可真熱鬧早处,春花似錦、人聲如沸瘫析。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)贬循。三九已至么库,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間甘有,已是汗流浹背诉儒。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留亏掀,地道東北人忱反。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像滤愕,于是被迫代替她去往敵國(guó)和親温算。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355

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

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理间影,服務(wù)發(fā)現(xiàn)注竿,斷路器,智...
    卡卡羅2017閱讀 134,657評(píng)論 18 139
  • 1. 概述 在網(wǎng)絡(luò)環(huán)境中一般用戶只需要在瀏覽器中輸入url如www.sunny.com就可以到對(duì)應(yīng)服務(wù)器獲取相應(yīng)的...
    ghbsunny閱讀 2,894評(píng)論 0 7
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,146評(píng)論 25 707
  • 最近很多次魂贬,隱約之間感到巩割,有一種緣分在默默的堆積,悄悄的釋放付燥,正是時(shí)候宣谈。 就拿最近的事情來(lái)說(shuō),正愁著某個(gè)重要的工作...
    自在牛閱讀 211評(píng)論 0 1
  • 回想起在做愿景板的過(guò)程中键科,內(nèi)心充滿想象闻丑,尋找符合心意的圖片,細(xì)分目標(biāo)勋颖,發(fā)現(xiàn)障礙嗦嗡,尋找對(duì)策,一步步完成完善饭玲,內(nèi)心不斷...
    田心遠(yuǎn)閱讀 1,029評(píng)論 10 9