Puppet 資源公有屬性的其餘描述方式web
puppet的資源公有屬性中還能夠經過"->"和"~>"兩種特殊符號來描述資源與資源之間的關係.bash
->:用於表示資源與資源之間的前後關係,等同於before和require兩個資源公有屬性.app
~>:用於表示資源之間的通知,等同於notify和subscribe練個資源公有屬性.dom
示例: "->"用法ide
安裝httpd並運行httpd服務的puppet代碼以下:ui
[root@sh-web1 ~]# cat httpd2.pp package {"httpd": ensure => present, provider => 'yum', } service {"httpd": ensure => running, enable => true, } Package["httpd"] -> Service["httpd"]
運行結果:spa
[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...
生產上並不會像上面那樣去寫,一個資源可能很大,篇幅很長.it
以下兩種寫法:
第一種:
[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