通用
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.