日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Puppet 资源公有属性的其他描述方式(三十)

發布時間:2023/12/15 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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, }


[root@sh-web1?~]#?puppet?apply?httpd2.pp? Notice:?Compiled?catalog?for?sh-web1.localdomain?in?environment?production?in?0.04?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?2.28?seconds


注意:大部分都是第二種寫法,"->"或"~>"跟在花括號的后面,但是個人習慣用第一種反正更新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 资源公有属性的其他描述方式(三十)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。