失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Puppet File资源介绍(贰拾)

Puppet File资源介绍(贰拾)

时间:2022-10-01 14:24:24

相关推荐

Puppet File资源介绍(贰拾)

puppet file资源常用的参数:

file{pathensurebackupchecksumcontentforcegrouplinksmodeownersourceselinux_ignore_defaultselrangeselroleseltypeseluser}

path:指定要管理的文件或目录,必须用引号引起来.

ensure:有5个值,分别是absent,present,file,directory,link.设置present值表示【匹配文件,它会检查path值中的路径文件是否存在,如果不存在就会创建;设置absent值,删除已经存在的文件;设置directory表示创建目录,但是要删除目录需增加参数force=>true,设置link时会根据path路径创建软连接文件.

示例:

删除目录

[root@sh-web1~]#ls/tmp/test[root@sh-web1~]#puppetapplydire.ppNotice:Compiledcatalogforsh-web1.localdomaininenvironmentproductionin0.06secondsNotice:/Stage[main]/Main/File[/tmp/test]/ensure:removedNotice:Finishedcatalogrunin0.05seconds[root@sh-web1~]#ls/tmp/[root@sh-web1~]#

backup:文件的内容在修改前是否备份,目前puppet支持两种备份方式,一种是将文件备份在agent上被修改文件的目录中,另一种方式将资源文件通过filebucket备份在远程服务器上。备份在agent上的方式,buckup属性的值如果是以".bak"开头的字符串的话,puppet会将变更文件备份在agent资源文件的同一目录下,备份文件的扩展名就是"."值里面的字符串,另一种远程备份需要借助filebucket资源.

示例:

file{"/tmp/test":ensure=>present,content=>"thisisfile.",backup=>".$backup_date.bak",}file{"/tmp/test":ensure=>present,content=>"thisistest.",backup=>".$backup_date.bak",}#puppetapplyfile2.ppNotice:Compiledcatalogforsh-web1.localdomaininenvironmentproductionin0.07secondsNotice:/Stage[main]/Main/File[/tmp/test]/content:contentchanged'{md5}70b7ea41998bea7dc5be44528ae37ba3'to'{md5}480fc0d368462326386da7bb8ed56ad7'Notice:Finishedcatalogrunin0.03seconds[root@sh-web1~]#ls/tmp/testtest..bak[root@sh-web1~]#cat/tmp/test..bakthisisfile.

注意:agent端主动备份会在file当前目录下备份.

checksum:检查文件内容是否被修改过,通过它可以检查文件的一致性。包括:md5,mtime,ctime默认使用md5.

content:可以向文件中追加内容或者通过调用template函数向erb模板中追加内容.

force:可以将一个目录变成一个连接,可用的值是true、false、yes和no,其中true与yes参数在这里均表示创建目录连接,false与no参数均表示不创建目录连接.

group:可以指定该文件的用户组,值可以使gid或系统组名.

links:定义操作符合连接的文件,可以设置的值是follow和manage.设置follow值文件复制时,会赋值文件的内容,而不是只复制连接本身;如果设置为manage值,则只复制符合连接本身.

mode:用于设置文件的权限.

owner:文件的属主.

source:指定源文件的位置,值可以是指定的远程文件的uris或者本地完整路径.

示例:

通过source同步puppet数组中多个文件.

file{source=>["puppet:///modules/nfs/conf.$host","puppet:///modules/nfs/conf.$operatingsystem","puppet:///modules/nfs/conf",]}

target:指定创建软连接的目标.

[root@sh-web1~]#catlink.ppfile{"/tmp/3.pp":ensure=>link,target=>'/root/3.pp',}[root@sh-web1~]#puppetapplylink.ppNotice:Compiledcatalogforsh-web1.localdomaininenvironmentproductionin0.06secondsNotice:/Stage[main]/Main/File[/tmp/3.pp]/ensure:createdNotice:Finishedcatalogrunin0.03seconds[root@sh-web1~]#ls/tmp/3.pptesttest..bak

selinux_ignore_default:selinux系列功能,实现自定义selinux.

selrange:selinux系列功能,定义范围.

selrole:selinux系列功能,定义角色.

seltype:selinux系列功能,定义类型.

seluser:selinux系列功能,定义用户.

filebucket资源示例:

filebucket资源主要用于文件的备份与恢复,通常与file资源配合使用.

filebucket{'':namepathportserver}

name:filebucket的名字.

path:服务器备份数据路径.

port:备份服务器的端口.

server:备份服务的域名.

示例:

nodebase{includeadminincludecronfilebucket{'main':server=>'puppet',path=>'/var/lib/puppet/clientbucket',}file{"/tmp/test":ensure=>present,content=>"thisislisi.",backup=>"main",}}node/sh-(proxy|web)\d+/inheritsbase{case$::hostname{/sh-proxy\d+/:{tag("web::proxy")includephp}"sh-web1":{includephp}}}

#puppetagent-tNotice:Ignoring--listenononetimerunInfo:RetrievingpluginfactsInfo:RetrievingpluginInfo:LoadingfactsInfo:Cachingcatalogforsh-web1.localdomainInfo:Applyingconfigurationversion'1507549594'Notice:/Stage[main]/Admin/Exec[selinux]/returns:executedsuccessfullyNotice:/Stage[main]/Main/Node[base]/File[/tmp/test]/content:---/tmp/test-10-0919:02:15.527825330+0800+++/tmp/puppet-file1009-5104-6zk5y1-0-10-0919:46:34.951821641+0800@@-1+1@@-thisistest.\Nonewlineatendoffile+thisislisi.\NonewlineatendoffileInfo:Computingchecksumonfile/tmp/testInfo:/Stage[main]/Main/Node[base]/File[/tmp/test]:Filebucketed/tmp/testtomainwithsum480fc0d368462326386da7bb8ed56ad7Notice:/Stage[main]/Main/Node[base]/File[/tmp/test]/content:contentchanged'{md5}480fc0d368462326386da7bb8ed56ad7'to'{md5}b58ff837e1152bf6d13212d1860c1219'Notice:Finishedcatalogrunin0.39seconds

注意:当资源改变时agent更新就会提示备份.

puppet 3.8的版本发现个问题:

master端并未备份到puppet 代码指定的位置:

[root@puppete]#tree.└──8└──d└──6└──1└──0└──f└──1e8d610ffbe27bf880c7d734386dbde1├──contents└──paths7directories,2files

[root@puppete]#pwd/var/lib/puppet/bucket/1/e

客户端备份到了path的路径:

[root@sh-web11]#tree.└──8└──6└──f└──3└──1└──9└──2└──186f319242818f98380d6369593bfb47├──contents└──paths8directories,2files

[root@sh-web11]#pwd/var/lib/puppet/clientbucket/1

如果觉得《Puppet File资源介绍(贰拾)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。