puppet基础使用(单机)
来源:互联网 发布:全国电子数据取证竞赛 编辑:程序博客网 时间:2024/05/15 04:30
puppet常用的资源类型大致有以下几种:
可以使用命令查看
[root@centos7 ~]# puppet describe -l
cron
exec
file
group
host
mount
notify
package
resources
service
ssh_authorized_key
sshkey
user
下面是常用的资源类型的具体用法。
group类型属性:
name:组名;
gid:GID;
system:是否为系统组,trueOR false;
nsure:目标状态,present/absent;
members:成员用户
示例1:vim group.ppgroup{'mygrp':
name => 'mygrp',
ensure => present,
gid => 2000,
}
user类型属性:name:用户名;
uid:UID;
gid:基本组ID;
groups:附加组,不能包含基本组;
comment:注释;
expiry:过期时间;
home:家目录;
shell:默认shell类型;
system:是否为系统用户;
ensure:present/absent;
password:加密后的密码串;
示例2:vim user1.pp
user{'mageedu':
ensure => present,
system => false,
comment => 'Test User',
shell => '/bin/zsh',
home => '/tmp/mageedu',
managehome => true,
groups => 'mygrp',
uid => 3000,}
示例3:vim user3.pp
group{'redhat':
ensure => present,
}
user{'ilinux':
comment => "ilinux.io",
ensure => present,
groups => ['redhat',],
require => Group['redhat'],
}
package类型属性:
ensure:installed,present, latest, absent, any version string (implies present)
name:包名;
source:程序包来源,仅对不会自动下载相关程序包的provider有用,例如rpm或dpkg;
provider:指明安装方式;
示例4:vim pkg1.pppackage{'redis':
ensure => latest,
provider => yum,
}
service类型属性:
ensure:Whethera service should be running. Valid values are `stopped` (also called `false`),`running` (also called `true`).
enable:Whethera service should be enabled to start at boot. Valid values are `true`, `false`,`manual`.
name:
path:Thesearch path for finding init scripts. Multiple values should be separated by colons or provided as an array.脚本的搜索路径,默认为/etc/init.d/;
hasrestart:
hasstatus:
start:手动定义启动命令;
stop:
status:
restart:Specifya *restart* command manually. If leftunspecified, the service will be stopped and then started. 通常用于定义reload操作;
示例5:vim srv1.pp
service{'redis':
ensure => running,
enable => true,
}
file类型属性:
ensure:Whetherthe file should exist, and if so what kind of file it should be. Possiblevalues 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:时间戳;
onlyif:此属性指定一个命令,此命令正常(退出码为0)运行时,当前command才会运行;
unless:此属性指定一个命令,此命令非正常(退出码为非0)运行时,当前command才会运行;
refresh:重新执行当前command的替代命令;
refreshonly:仅接收到订阅的资源的通知时方才运行;
示例6:vim file1.ppfile{'/tmp/redis.conf':
ensure => file,
source =>'/root/manifests/files/redis.conf',
}
示例7:vim file2.pp
file{'/tmp/test.txt':
ensure => file,
content => 'How are you?/nHow oldare you?/n',
owner => 'mageedu',
group => 'mygrp',
mode => '0400',
}cron类型属性:
command:要执行的任务;
ensure:present/absent;
hour:
minute:
monthday:
month:
weekday:
user:以哪个用户的身份运行命令
target:添加为哪个用户的任务
name:cronjob的名称;
示例8:vim cron.ppcron{'timesync':
command => '/usr/sbin/ntpdate 172.16.0.1&> /dev/null',
ensure => present,
minute => "*/5",
target => 'root'
}
notify类型属性:
message:信息内容
name:信息名称;
示例9:vim notify.pp
notify{'sayhi':
message => "hi there",
}
exec类型属性:
cwd:Thedirectory from which to run the command.
**creates**:文件路径,仅此路径表示的文件不存在时,command方才执行;
user/group:运行命令的用户身份;
path:Thesearch path used for command execution. Commands must be fully qualified if nopath is specified.
onlyif:此属性指定一个命令,此命令正常(退出码为0)运行时,当前command才会运行;
unless:此属性指定一个命令,此命令非正常(退出码为非0)运行时,当前command才会运行;
refresh:重新执行当前command的替代命令;
refreshonly:仅接收到订阅的资源的通知时方才运行;
示例10:vim exec1.pp
exec{'cmd':
command => 'mkdir /tmp/testdir',
path =>['/bin','/sbin','/usr/bin','/usr/sbin'],
creates =>'/tmp/testdir',#目录不存在,则创建,存在,则不创建
}
puppet流程控制语句:
1、if
if$operatingsystemmajrelease == '7' {
$db_pkg='mariadb-server'
} else {
$db_pkg='mysql-server'
}
package{"$db_pkg":
ensure => installed,
}
2、case
case $osfamily {
'RedHat': { $webPkg='httpd' }
/(?i-mx:debian)/: { $webPkg='apache2' }
default: { $webPkg='apache' }
}
package{'$webPkg':
ensure => installed,
}
3、Selector
vim seleceor.pp
#wen server
$webPkg = $osfamily? {
'RedHat' => 'httpd',
/(?-mx:debian)/ => 'aache2',
defaule => 'apache'
}
package{'$webPkg':
ensure => installed,
}
具有依赖关系的语句:before,require,也可以用->表示。示例:vim redis.pp
package{'redis':
ensure => installed,
}
file{'/etc/redis.conf':
source =>'/root/manifests/files/redis.conf',
ensure => file,
owner => redis,
group => root,
mode => '0640',
# notify => Service['redis'],
}
service{'redis':
ensure => running,
enable => true,
#require =>['Package["redis"]','File["/etc/redis.conf"]'],
hasrestart => true,#为true是reload,若是为false,则是先stop,再start.
}
Package['redis']-> File['/etc/redis.conf'] -> Service['redis']
最后执行命令:
[root@node1 manifests]#puppet apply -v pkg1.pp#运行puppet脚本
- puppet基础使用(单机)
- Puppet基础之单机模型
- (2)puppet单机测试命令apply
- puppet基础学习(一)
- puppet基础学习(二)
- puppet安装和使用
- puppet中exec使用
- puppet安装使用
- puppet 使用Apache+passenger
- Puppet以及Dashboard安装使用(含文档)
- 自动化运维工具puppet一:puppet资源及单机模型
- Puppet基础篇6-Puppet更新方式的选型
- puppet笔记(1)
- puppet
- Puppet
- puppet
- puppet
- Puppet
- pwntools的常见用法
- homestead错误Your VM has become "inaccessible."
- 459. Repeated Substring Pattern
- Linux内核之进程
- 成功者的32条箴言
- puppet基础使用(单机)
- 解决在hex中系统按钮消失问题
- Java--request,response
- JSP指令与动作元素
- pip安装依赖于six的库错误解决方案
- 信号的捕获和处理
- [Spring]Spring中的事务管理
- [转]HUSTOJ出现RuntimeError,正确姿势。
- ubuntu16.04 安装网易云音乐