通用
1、puppet describe -l 檢視puppet支援的資源類型
puppet describe typename 檢視某個資源類型的Parameters,Providers--詳細
puppet describe -s typename -m 檢視某個資源的參數等--簡單
2、puppet apply [-d|--debug] [-v|--verbose] [-e|--execute] [--noop] <file>
puppet help apply 檢視幫助
puppet apply -v 檢視詳情
-d 調試模式
-l 儲存在指定檔案中
--noop 幹跑,不執行
一、group:
1、Manage groups
屬性:
name:組名;
gid:GID;
system:是否為系統組,true OR false;
ensure:目标狀态,present/absent;
members:成員使用者;
2、例子:建立組
(1) vim group.pp
group{'mygrp':
ensure => present
}
(2)執行
puppet apply -v --noop group.pp 先看看是否有錯
puppet apply -v group.pp 真正執行
二、user
1、Manage users.
name:使用者名;
uid: UID;
gid:基本組ID;
groups:附加組,不能包含基本組;
comment:注釋;
expiry:過期時間 ;
home:家目錄;
shell:預設shell類型;
system:是否為系統使用者 ;
ensure:present/absent;
password:加密後的密碼串;
2、例子:建立使用者
(1)使用者名為user2,不寫name。預設是跟title一直,都是user2
vim user.pp
user{'user2':
ensure => present,
uid => 1021,
groups => 'redhat',
puppet apply -v --noop user.pp
puppet apply -v user.pp
三、package
1、Manage packages.
ensure:installed, present, latest, absent, any version string (implies present)
name:包名;
source:程式包來源,僅對不會自動下載下傳相關程式包的provider有用,例如rpm或dpkg;
provider:指明安裝方式;
2、例子:安裝包
安裝memcached包
package{'memcached':
ensure => installed,
四、service
1、Manage running services.
ensure:Whether a service should be running. Valid values are
stopped
(also called
false
),
running
true
)
enable:Whether a service should be enabled to start at boot. 開機啟動Valid values are
true
,
false
manual
.
name:
path:The search path for finding init scripts. Multiple values should be separated by colons or provided as an array. 腳本的搜尋路徑,預設為/etc/init.d/;
hasrestart:true |false false :init 腳本中的restart指令将不能用,使用stop ,start,預設false
hasstatus:true|false stasus 指令是否使用
start:手動定義啟動指令;
stop:
status:
restart:Specify a restart command manually. If left unspecified, the service will be stopped and then started. 通常用于定義reload操作;
2、例子:安裝包并啟動服務
service{'memcached':
ensure => running,
enable => false,
五、file
1、Manages files, including their content, ownership, and permissions. 管理檔案,包括它們的内容、所有權和權限。
ensure:Whether the file should exist, and if so what kind of file it should be. Possible values are
present
absent
file
directory
, and
link
file:類型為普通檔案,其内容由content屬性生成或複制由source屬性指向的檔案路徑來建立;
link:類型為符号連結檔案,必須由target屬性指明其連結的目标檔案;
directory:類型為目錄,可通過source指向的路徑複制生成,recurse屬性指明是否遞歸複制;
path:檔案路徑;
source:源檔案;
content:檔案内容;
target:符号連結的目标檔案;
owner:屬主
group:屬組
mode:權限;
atime/ctime/mtime:時間戳;
2、例子
(1)例子1:将'/root/manifects/files/redis.conf 的檔案複制到/tmp/redis.conf
file{'/tmp/redis.conf':
ensure => file,
source => '/root/manifects/files/redis.conf',
(2)例子2:基于内容複制
将hello
hi 内容給/tmp/test.txt
file{'/tmp/test.txt':
content => "hello\nhi\n",
六、exec
1、Executes external commands. Any command in an
exec
resource must be able to run multiple times without causing harm --- that is, it must be idempotent.