Puppet--文件自动化管理

简介:

Puppet文件自动化管理

一.安装后的目录结构

安装目录默认存为/etc/puppet,该目录下的manifests存放manifest文件。其他可执行文件在/user/sbin下,主要有:

puppet 用于执行用户所写独立的mainfests文件

puppetd 运行在被管理主机上的客户端程序

puppetmasterd:运行在管理机上的服务器程序

puppetcapuppet认证程序,主要用于对client的证书进行认证

puppetrun:用于连接客户端,强制运行本地配置文件

file资源:  管理系统本地文件

设置文件权限和属主

管理文件内容,可以基于模板的内容管理

支持管理目录

从远程服务器复制整个目录到本地

参数

Backup:决定文件的内容在被修改前是否进行备份.

Checksum:检查文件是否被修改,这个状态用来在复制文件的时候使用检测方式包括md5 ,mtime等。默认的检测是用md5

Content:把文件的内容设置为content 参数后面的字符串

Ensure:如果文件本来不存在是否要新建文件,可以设置的值是 absentpresent,filedirectory. 如果指定 present,就会检查该文件是否存在,如果不存在就新建该文件,如果指定是 absent, 就会删除该文件(如果recurse => true ,就会删除目录),如果提供的值不是上面提到的4,那么就会创建一个文件的符号链接.

Force:作用是用在把一个目录变成一个链接,可用的值是turefalse

Group:指定那个该文件的用户组,值可以是gid或者组名

    Ignore:当用recursion 方法复制一个目录的时候,可以用ignore来设定过滤条件,符合过滤条件的文件不被复制.

Links:定义操作符合链接文件可以设置的值是followmanage; 文件拷贝的时候,设置follow,会拷贝文件的内容,而不是只拷贝符合链接本身,如果设置成manage ,会拷贝符合链接本身.

Modemode用于设置文件的权限

Owner:设置文件的属主

Path:指定要管理文件的路径,必须用引号引起来这也是一个资源的 namevar ,通常path 等于资源的title

Recurse:设置是否以及如何进行递归操作可以设置的值是 false,ture ,inf ,remote

Recurselimit:递归的深度,设置的值可以匹配/^[0-9]+$/.

Source:拷贝一个文件覆盖当前文件,checksum来判断是否有必要进行复制,可以设置的值是一个引用的完整的文件路径,或者是URI,当前支持的URI只有puppetfile ;

File资源测试用例

登陆puppet master,编辑默认manifest文件site.pp

 
 
  1. [root@master ~]# cd /etc/puppet/manifests/ 
  2.  
  3. [root@master manifests]# vim site.pp 
  4.  
  5.  node default { 
  6.  
  7.           file {'file1'
  8.  
  9.               path => '/tmp/file1'
  10.  
  11.               ensure => present, 
  12.  
  13.               mode => 0777
  14.  
  15.               user => root, 
  16.  
  17.               group => root, 
  18.  
  19.               content => "Welcome to use Puppet."
  20.  
  21.           
  22.  
  23.          } 
  24.  
  25.      } 

puppet master应用该测试文件

 
 
  1. [root@master manifests]# puppet apply file1.pp 
  2.  
  3. notice: /Stage[main]//File[file1]/ensure: created 
  4.  
  5. notice: Finished catalog run in 0.04 seconds 

检查puppet master上是否生效

 
 
  1. [root@master manifests]# more /tmp/file1 
  2.  
  3. Welcome to use Puppet. 
  4.  
  5. [root@master manifests]# ll /tmp/file1 
  6.  
  7. -rwxrwxrwx 1 root root 22  2月 22 15:13 /tmp/file1 

用其中一个客户端测试

 
 
  1. [root@client1 puppet]# puppetd   --server  master.puppet --test 
  2.  
  3. notice: Ignoring --listen on onetime run 
  4.  
  5. info: Caching catalog for client1.centos 
  6.  
  7. info: Applying configuration version '1329902782' 
  8.  
  9. notice: /Stage[main]//Node[default]/File[file1]/ensure: created 
  10.  
  11. notice: Finished catalog run in 0.01 seconds 

       查看客户端文件属性

 
 
  1. [root@client1 puppet]# ls -l /tmp/file1 
  2.  
  3. -rwxrwxrwx 1 root root 22  2月 22 17:26 /tmp/file1 
  4.  
  5. [root@client1 puppet]# more /tmp/file1 
  6.  
  7. Welcome to use Puppet. 

 

出现的问题1,报错如下:

 
 
  1. [root@client3 ~]# puppetd  --test --server master.puppet 
  2.  
  3. err: Could not retrieve catalog from remote server: Error 400 on SERVER: No support for http method POST 
  4.  
  5. warning: Not using cache on failed catalog 
  6.  
  7. err: Could not retrieve catalog; skipping run 
  8.  
  9. notice: /File[/var/puppet/state/last_run_summary.yaml]/content: 
  10.  
  11. --- /var/puppet/state/last_run_summary.yaml     2012-02-23 09:13:50.000000000 +0800 
  12.  
  13. +++ /tmp/puppet-file20120223-4772-1la6w5s-0     2012-02-23 09:14:59.000000000 +0800 
  14.  
  15. @@ -3,4 +3,4 @@ 
  16.  
  17.      puppet: 2.7.10 
  18.  
  19.      config: 
  20.  
  21.    time: 
  22.  
  23. -    last_run: 1329959630 
  24.  
  25. \ No newline at end of file 
  26.  
  27. +    last_run: 1329959699 
  28.  
  29. \ No newline at end of file 

出现这个报错的原因是因为puppet的客户端版本和服务器的版本不一样导致的,puppet master的版本是2.6.13,而puppet client的版本是2.7.10下面是检查版本:

 
 
  1. [root@master ~]# puppetmasterd --version 
  2.  
  3. 2.6.13 

安装2.6.13的客户端恢复


 
 
  1. [root@client3 ~]# fetch http://puppetlabs.com/downloads/puppet/puppet-2.6.13.tar.gz 
  2.  
  3. [root@client3 ~]# tar -zxvf puppet-2.6.13.tar.gz 
  4.  
  5. [root@client3 ~]# cd puppet-2.6.13 
  6.  
  7. [root@client3 ~/puppet-2.6.13]# ruby  install.rb 
  8.  
  9. [root@client3 ~]# puppetd --version 
  10.  
  11. 2.6.13 

       出现的问题2,证书问题,报错如下

 
 
  1. [root@client3 /var/lib/puppet]# puppetd  --test  --server  master.puppet 
  2.  
  3. err: Could not request certificate: Retrieved certificate does not match private key; please remove certificate from server and regenerate it with the current key 
  4.  
  5. Exiting; failed to retrieve certificate and waitforcert is disabled 

        清楚服务器端的证书,重新认证,如仍然报错可以将客户端的ssl正式也删除

 
 
  1. [root@master ssl]# puppetca --clean  client3.freebsd 
  2.  
  3. notice: Revoked certificate with serial 7 
  4.  
  5. notice: Removing file Puppet::SSL::Certificate client3.freebsd at '/var/lib/puppet/ssl/ca/signed/client3.freebsd.pem' 
  6.  
  7. notice: Removing file Puppet::SSL::Certificate client3.freebsd at '/var/lib/puppet/ssl/certs/client3.freebsd.pem' 

 
 
  1. [root@client3 ~]# cd /etc/puppet/ 
  2.  
  3. [root@client3 /etc/puppet]# mv ssl  ssl_bak 

   重新认证,客户端恢复

 
 
  1. [root@client3 ~]# puppetd  --test  --server  master.puppet        
  2.  
  3. info: Caching catalog for client3.freebsd 
  4.  
  5. info: Applying configuration version '1329961887' 
  6.  
  7. notice: Finished catalog run in 0.02 seconds 

       测试file资源的其他参数

 
 
  1. [root@master ~]# vim /etc/puppet/manifests/site.pp 
  2.  
  3. node default { 
  4.  
  5.           file {'file1'
  6.  
  7.               path => '/tmp/file1'
  8.  
  9.               ensure => present, 
  10.  
  11.               mode => 0777
  12.  
  13.               #user => root, 
  14.  
  15.               #group => root, 
  16.  
  17.               content => "Welcome to use Puppet."
  18.  
  19.           } 
  20.  
  21.   
  22.  
  23.           file{ '/tmp/file2'
  24.  
  25.               ensure => directory, 
  26.  
  27.               mode=>0644
  28.  
  29.           } 
  30.  
  31.   
  32.  
  33.           file{'/tmp/file3'
  34.  
  35.               ensure=>link, 
  36.  
  37.               target=>'/tmp/file1'
  38.  
  39.           } 
  40.  
  41.   
  42.  
  43.      } 

      客户端测试配置

 
 
  1. [root@client1 ~]# puppetd   --server  master.puppet --test 
  2.  
  3. notice: Ignoring --listen on onetime run 
  4.  
  5. info: Caching catalog for client1.centos 
  6.  
  7. info: Applying configuration version '1329963133' 
  8.  
  9. notice: /Stage[main]//Node[default]/File[/tmp/file2]/ensure: created 
  10.  
  11. notice: /Stage[main]//Node[default]/File[/tmp/file3]/ensure: created 
  12.  
  13. notice: Finished catalog run in 0.03 seconds 

       查看生成文件信息

 
 
  1. [root@client1 ~]# ls -l /tmp/file* 
  2.  
  3. -rwxrwxrwx 1 root root   22  2月 22 17:26 /tmp/file1 
  4.  
  5. lrwxrwxrwx 1 root root   10  2月 23 10:12 /tmp/file3 -> /tmp/file1 
  6.  
  7.   
  8.  
  9. /tmp/file2: 
  10.  
  11. 总用量 0 

 










本文转自 waydee 51CTO博客,原文链接:http://blog.51cto.com/waydee/847118,如需转载请自行联系原作者
目录
相关文章
|
3月前
|
BI Python
python报表自动化系列 - 获取指定目录所有文件绝对路径
python报表自动化系列 - 获取指定目录所有文件绝对路径
27 0
|
3月前
|
Shell Linux
shell 脚本常用于自动化执行文件备份与压缩的任务
shell 脚本常用于自动化执行文件备份与压缩的任务
29 1
|
2月前
|
数据采集 机器学习/深度学习 数据可视化
【办公自动化】使用Python批量处理Excel文件并转为csv文件
【办公自动化】使用Python批量处理Excel文件并转为csv文件
48 0
|
2月前
|
存储 自然语言处理 数据可视化
【办公自动化】用Python按时间分割txt文件中的数据
【办公自动化】用Python按时间分割txt文件中的数据
55 1
|
2月前
|
编解码 数据可视化 数据挖掘
【办公自动化】用Python将PDF文件转存为图片
【办公自动化】用Python将PDF文件转存为图片
63 1
|
3月前
|
数据可视化 Python
Python办公自动化【合并单元格-openpyxl、增加图表-openpyxl、合并工作薄-openpyxl、合并多个文件工作薄-openpyxl】(三)-全面详解(学习总结---从入门到深化)(上)
Python办公自动化【合并单元格-openpyxl、增加图表-openpyxl、合并工作薄-openpyxl、合并多个文件工作薄-openpyxl】(三)-全面详解(学习总结---从入门到深化)
104 2
|
2月前
|
数据安全/隐私保护 Python Windows
Python办公自动化【Word转换PDF、PDF读取内容、PDF合并文件、PDF拆分文件、PDF加密文件、PPT基本操作-增加幻灯片、增加内容】(六)-全面详解(学习总结---从入门到深化)
Python办公自动化【Word转换PDF、PDF读取内容、PDF合并文件、PDF拆分文件、PDF加密文件、PPT基本操作-增加幻灯片、增加内容】(六)-全面详解(学习总结---从入门到深化)
47 0
|
2月前
|
数据可视化 Python
Python办公自动化【合并单元格-openpyxl、增加图表-openpyxl、合并工作薄-openpyxl、合并多个文件工作薄-openpyxl】(三)-全面详解(学习总结---从入门到深化)
Python办公自动化【合并单元格-openpyxl、增加图表-openpyxl、合并工作薄-openpyxl、合并多个文件工作薄-openpyxl】(三)-全面详解(学习总结---从入门到深化)
44 0
|
3月前
|
BI Python
python报表自动化系列 - 按照文件名筛选文件
python报表自动化系列 - 按照文件名筛选文件
27 2
|
3月前
|
存储 JSON API
Python 自动化指南(繁琐工作自动化)第二版:十六、使用 CSV 文件和 JSON 数据
Python 自动化指南(繁琐工作自动化)第二版:十六、使用 CSV 文件和 JSON 数据
66 1

热门文章

最新文章

推荐镜像

更多