天天看點

puppet 基礎-建立第一個配置

一個節點的目錄結構可以任意定義,隻要在site.pp配置檔案中import即可。

建議采用如下目錄結構配置: 節點資訊:/etc/puppet/manifests/nodes 子產品資訊:/etc/puppet/modules

現在學習配置簡單的File資源,建立檔案,并寫入’Hello World‘。

1.建立file-helloworld子產品 mkdir -p /etc/puppet/modules/ file-helloworld/{manifests,templates,files } vim   /etc/puppet/modules/ file-helloworld/ manifests/init.pp class file-helloworld {   file { "/root/hostname.txt": content => "Hello world!";} } 2.建立測試節點app-192.168.9.158.centos.test.com mkdir -p /etc/puppet/manifests/nodes node 'app-192.168.9.158.centos.test.com' {   include file-helloworld } 3.最後将測試節點載入到Puppet,也就是修改site.pp配置檔案。 vim /etc/puppet/manifests/site.pp 追加一行 import "nodes/app-192.168.9.158.centos.test.com.pp"

到此一個測試節點配置完畢,接下來需要檢查配置檔案的文法。

檢查配置檔案分兩步經行 第一步在服務端 puppet parser validate /etc/puppet/modules/file-helloworld/manifests/init.pp

看是否提示錯誤,無錯誤提示則經行下一步。

第二步在用戶端 通過添加--noop參數來實作,驗證配置,模拟執行。 [[email protected] ~]# puppet agent --test --noop Info: Retrieving pluginfacts Info: Retrieving plugin Info: Caching catalog for app-192.168.9.158.centos.test.com Info: Applying configuration version '1464588576' Notice: /Stage[main]/File-helloworld/File[/root/hostname.txt]/ensure: current_value absent, should be file (noop) Notice: Class[File-helloworld]: 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

用戶端運作配置 [[email protected] ~]# puppet agent --test  Info: Retrieving pluginfacts Info: Retrieving plugin Info: Caching catalog for app-192.168.9.158.centos.test.com Info: Applying configuration version '1464588576' Notice: /Stage[main]/File-helloworld/File[/root/hostname.txt]/ensure: defined content as '{md5}86fb269d190d2c85f6e0468ceca42a20' Notice: Finished catalog run in 0.24 seconds 檢視運作結果 [[email protected] ~]# ll hostname.txt  -rw-r--r-- 1 root root 12 5月  30 14:13 hostname.txt

繼續閱讀