大家好,欢迎来到IT知识分享网。
file:
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:时间戳;
资源有特殊属性:
名称变量(namevar):
name可省略,此时将由title表示;
ensure:
定义资源的目标状态;
元参数:metaparameters
依赖关系:
before
require
通知关系:通知相关的其它资源进行“刷新”操作;
notify
A notify B:B依赖于A,且A发生改变后会通知B;
{
…
notify => Type[‘B’],
…
}
subscribe
B subscribe A:B依赖于A,且B监控A资源的变化产生的事件;
{
…
subscribe => Type[‘A’],
…
}
示例1:
file{‘test.txt’:
path => ‘/tmp/test.txt’,
ensure => file,
source => ‘/etc/fstab’,
}
file{‘test.symlink’:
path => ‘/tmp/test.symlink’,
ensure => link,
target => ‘/tmp/test.txt’,
require => File[‘test.txt’],
}
file{‘test.dir’:
path => ‘/tmp/test.dir’,
ensure => directory,
source => ‘/etc/yum.repos.d/’,
recurse => true, #如果这里recurse => limit 则是限制目录层级到多少层
}
源为文件或多个文件,目标为目录,则复制过去也是文件,
示例2:
service{‘httpd’:
ensure => running,
enable => true,
restart => ‘systemctl restart httpd.service’,
# subscribe => File[‘httpd.conf’],
}
package{‘httpd’:
ensure => installed,
}
file{‘httpd.conf’:
path => ‘/etc/httpd/conf/httpd.conf’,
source => ‘/root/manifests/httpd.conf’,
ensure => file,
notify => Service[‘httpd’],
}
Package[‘httpd’] -> File[‘httpd.conf’] -> Service[‘httpd’]
exec:
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.
command (namevar):要运行的命令;
cwd:The directory from which to run the command.
creates:文件路径,仅此路径表示的文件不存在时,command方才执行;
user/group:运行命令的用户身份;
path:The search path used for command execution. Commands must be fully qualified if no path is specified.
onlyif:此属性指定一个命令,此命令正常(退出码为0)运行时,当前command才会运行;
unless:此属性指定一个命令,此命令非正常(退出码为非0)运行时,当前command才会运行;
refresh:重新执行当前command的替代命令;
refreshonly:仅接收到订阅的资源的通知时方才运行;
cron:
Installs and manages cron jobs. Every cron resource created by Puppet requires a command and at least one periodic attribute (hour, minute, month, monthday, weekday, or special).
command:要执行的任务;
ensure:present/absent;
hour:
minute:
monthday:
month:
weekday:
user:以哪个用户的身份运行命令
target:添加为哪个用户的任务
name:cron job的名称;
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/138094.html