常用的資源類型:
notify, cron, exec, service, file, package, group, user
(1) notify:利用puppet定義一個信息。
message:通知的信息內容
notify {'warning': message=> "From warning notify resource.", }
(2) cron
ensure: 目標狀態
command: 命令
hour
minute
month
monthday
weekday
name: 名稱
user: 接收此任務的用戶
environment: 運行時的環境變量
cron {'message': minute=> '*/10', command=> '/bin/echo "puppet"', name=> 'echo something', ensure=> present, }
(3) exec
command (NameVar):要執行命令;必須冪等的;
creates:此屬性指定的文件不存在時才執行此資源;
onlyif: 此屬性指定的測試條件返回成功狀態碼時,才運行此資源指定的命令;
unless: 此屬性指定的測試條件返回錯誤狀態碼時,才運行此資源指定的命令;
user: 以此屬性指定的用戶身份運行資源指定的命令;
group:
path: 命令的搜索路徑合集;
cwd:在此屬性指定的路徑下運行此命令;
refresh: 定義如何refresh此資源;當此exec資源接收到其它資源的事件通知時的默認行爲是再運行一次此資源,refresh屬性就用於改變這種默認行爲;
refreshonly:僅在收到refresh通知時才執行此exec資源指定的命令;
timeout: 命令運行超時時長;
tries: 嘗試運行的次數;
exec {'test': command=> 'echo "hi from exec again" >> /tmp/hello.puppet', path => '/bin:/sbin:/usr/bin:/usr/sbin', unless=> 'test -f /tmp/hello.puppet', }
注意:如果不指定path屬性,則命令必須爲絕對路徑,且shell內建命令可能無法運行;
(4) file
content:直接給定文件內容;
source: 複製此屬性指定的文件爲此file定義的文件的內容;
recurse: 如果source指定的路徑爲目錄可遞歸傳輸整個目錄;true or false;
checksum: 指定使用何種方式檢查文件內容是否發生改變;
ctime:
mtime:
ensure: 文件存在與否及其文件類型
如果文件本來不存在是否要新建文件,可以設置的值是 absent和present,file和directory. 如果指定 present,就會檢查該文件是否存在,如果不存在就新建該文件,如果指定是 absent, 就會刪除該文件(如果recurse => true ,就會刪除目錄)
file, directory, link, present, absent
target: 當ensure爲link時,指定鏈接的源文件;
force:強制運行與否;
owner: 屬主
group: 屬組
links:複製時如何處理鏈接文件,follow, ignore, manage;
mode: 權限
path: NameVar,文件路徑;
file {'/tmp/mydir': ensure=> directory, } file {'/tmp/mydir/test.txt': content=> 'hello from file resource', ensure=> file, } file {'/tmp/mydir/fstab.puppet': source=> '/etc/fstab', ensure=> file, } file {'/tmp/mydir/fstab.link': target=> '/tmp/mydir/fstab.puppet', ensure=> link, } file {'/tmp/pam.puppet': source=> '/etc/pam.d', recurse=> true, ensure=> directory, }
(5) group
name: 組名,NameVar
gid: GID
system: 是否爲系統組;
group {'mygrp': gid=> 2000, system=> false, }
(6) user
comment:註釋
ensure:
expiry: 過期時間
gid: 基本組
groups: 附加組
managehome: 是否讓家目錄具有“可管理性”;
home: 家目錄路徑
shell: 默認shell;
system: 是否爲系統用戶;
uid: UID
name: NameVar,用戶名;
password:密碼
password_max_age:
password_min_age:
group {'mysql': ensure=> present, system=> true, gid=> 306, }
group {'dbusers': ensure=> present, gid=> 3306, }
user {'mysql': ensure=> present, uid=> 306, gid=> 306, groups=> 'dbusers', system=> true, }
(7) package
ensure: present, absent, latest, installed或版本號;
name: 程序包名,NameVar;
source:程序包來源;
provider: 指定要使用包管理器;
package{'zsh': ensure=> installed, }
package{'nginx': ensure=> installed, provider => rpm, source=> '/tmp/nginx-1.6.2-1.el6.ngx.x86_64.rpm', }
(8) service
ensure:running, true; stopped, false;
enable: 是否開機自動啓動;
hasrestart: 告訴puppet服務腳本是否運行使用“restart”參數;
hasstatus:告訴puppet服務腳本是否運行使用“status”參數;
name: 腳本名稱;
path: 腳本查找路徑
pattern: 指明搜索服務相關的進程的模式;用於當腳本不支持使用restart/status參數時幫助判定服務是否運行;
restart:手動指定用於服務“重啓”的命令;
start:
stop:
status:
package{'nginx': ensure=> installed, provider => rpm, source=> '/tmp/nginx-1.6.2-1.el6.ngx.x86_64.rpm', }
file {'/etc/nginx/conf.d/default.conf': ensure=> file, source=> '/tmp/default.conf', notify=> Service['nginx'], }
file {'/etc/nginx/nginx.conf': ensure=> file, source=> '/tmp/nginx.conf', notify=> Service['nginx'], }
service{'nginx': ensure=> running, enable=> true, require=> Package['nginx'], restart=> '/etc/rc.d/init.d/nginx reload', }