Puppet 资源公有属性的其他描述方式(三十)
生活随笔
收集整理的這篇文章主要介紹了
Puppet 资源公有属性的其他描述方式(三十)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Puppet 資源公有屬性的其他描述方式
puppet的資源公有屬性中還可以通過"->"和"~>"兩種特殊符號來描述資源與資源之間的關系.
->:用于表示資源與資源之間的先后關系,等同于before和require兩個資源公有屬性.
~>:用于表示資源之間的通知,等同于notify和subscribe練個資源公有屬性.
示例: "->"用法
安裝httpd并運行httpd服務的puppet代碼如下:
[root@sh-web1?~]#?cat?httpd2.pp? package?{"httpd":ensure?=>?present,provider?=>?'yum', } service?{"httpd":ensure?=>?running,enable?=>?true, } Package["httpd"]?->?Service["httpd"]運行結果:
[root@sh-web1?~]#?puppet?apply?httpd2.pp? Notice:?Compiled?catalog?for?sh-web1.localdomain?in?environment?production?in?0.06?seconds Notice:?/Stage[main]/Main/Package[httpd]/ensure:?created Notice:?/Stage[main]/Main/Service[httpd]/ensure:?ensure?changed?'stopped'?to?'running' Notice:?Finished?catalog?run?in?3.02?seconds [root@sh-web1?~]#?/etc/init.d/httpd?status httpd?(pid??81254)?is?running...示例: "~>"用法
[root@sh-web1?~]#?cat?httpd.pp? package?{"httpd":ensure?=>?present,provider?=>?'yum', } service?{"httpd":ensure?=>?running,enable?=>?true, } file?{'/etc/httpd/conf/httpd.conf':ensure?=>?file, } Package["httpd"]?->?File?['/etc/httpd/conf/httpd.conf']?~>?Service["httpd"]運行結果:
[root@sh-web1?~]#?puppet?apply?httpd.pp? Notice:?Compiled?catalog?for?sh-web1.localdomain?in?environment?production?in?0.07?seconds Notice:?/Stage[main]/Main/Package[httpd]/ensure:?created Notice:?/Stage[main]/Main/Service[httpd]/ensure:?ensure?changed?'stopped'?to?'running' Notice:?Finished?catalog?run?in?3.25?seconds [root@sh-web1?~]#?/etc/init.d/httpd?status httpd?(pid??81493)?is?running...生產上并不會像上面那樣去寫,一個資源可能很大,篇幅很長.
如下兩種寫法:
第一種:
[root@sh-web1?~]#?cat?httpd2.pp? package?{"httpd":ensure?=>?present, provider?=>?'yum', } -> service?{"httpd":ensure?=>?running, enable?=>?true, }第二種:
[root@sh-web1?~]#?cat?httpd2.pp? package?{"httpd":ensure?=>?present,provider?=>?'yum', }?-> service?{"httpd":ensure?=>?running,enable?=>?true, }注意:大部分都是第二種寫法,"->"或"~>"跟在花括號的后面,但是個人習慣用第一種反正更新puppet不報錯也能得到想要結果就ok.
audit審計
audit資源公有屬性主要用于資源屬性的審計,當某資源狀態變化時,它可以將變化的內容抓夾到系統日志中.
puppet代碼如下:
[root@sh-web1?~]#?cat?file.pp? file?{"/etc/password":audit?=>?[?owner,mode?], }運行過程,會看到改變通知.
[root@sh-web1?~]#?puppet?apply?file.pp? Notice:?Compiled?catalog?for?sh-web1.localdomain?in?environment?production?in?0.07?seconds Notice:?/Stage[main]/Main/File[/etc/password]/owner:?audit?change:?newly-recorded?value?absent Notice:?/Stage[main]/Main/File[/etc/password]/mode:?audit?change:?newly-recorded?value?absent Notice:?Finished?catalog?run?in?0.05?seconds總結
以上是生活随笔為你收集整理的Puppet 资源公有属性的其他描述方式(三十)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 配置信息曝光!小米13 Lite现身NB
- 下一篇: angularjs探秘五 举足轻重的sc