# Author:fairylly
1、puppet主服务器上的文件传输给puppet客户端
/etc/puppet/manifests/site.pp
file { 'Config.php':
path => '/var/www/html/luly/Config.php',
ensure => file,
source => 'puppet:///modules/www/Config.php',
owner => apache,
group => 'apache',
mode => 0644,
}
config.php:title文件名
path => '/var/www/html/Config.php':文件路径
ensure => file:确认为文件
source => 'puppet:///modules/www/Config.php':客户端从服务端该位置下载文件,即:/etc/puppet/modules/www/files/Config.php
(puppet:///modules目录,默认为:/etc/puppet/modules)
owner => apache:文件所属用户为apache
group => apache:文件所属组为apache
mode => 0644:文件权限为644
客户端执行:puppet agent -t
[root@mx /]# ll /var/www/html/luly/Config.php
-rw-r--r-- 1 apache apache 19 Oct 28 17:00 /var/www/html/luly/Config.php
[root@mx /]# cat /var/www/html/luly/Config.php
this is Config.php
注意:要确保客户端存在/var/www/html/路径,否则会出错;
2、puppet-exec之执行数据库脚本
/etc/puppet/manifests/site.pp
file { 'update_20131029.sql':
path => '/root/update_20131029.sql',
ensure => file,
source => 'puppet:///modules/sql/update_20131029.sql',
before => Exec['update_sql']
}
exec { 'update_sql':
command => '/usr/bin/mysql < /root/update_20131029.sql',
path => '/usr/bin'
}
file:
before => Exec['update_sql']:执行update_sql之前,先确认有/root/update_20131029.sql文件存在
(注意:调用Exec['update_sql'],Exec首字母要大写)
exec:
command => '/usr/bin/mysql < /root/update_20131029.sql':执行的命令
客户端执行:
[root@mx /]# puppet agent -t
Info: Retrieving plugin
Info: Caching catalog for puppetclient1.com
Info: Applying configuration version '1383035718'
Notice: /Stage[main]//File[update_20131029.sql]/ensure: defined content as '{md5}837a631949bee4b3824bda74df200d39'
Notice: /Stage[main]//Exec[update_sql]/returns: executed successfully
Notice: Finished catalog run in 0.50 seconds
3、puppet-exec之执行shell脚本
/etc/puppet/manifests/site.pp
file { 'update-131018.sh':
path => '/root/update-131018.sh',
ensure => file,
source => 'puppet:///modules/update_package/update-131018.sh',
owner => root,
mode => 0777,
before => Exec['update-131018']
}
file { 'update-131018.zip':
path => '/root/update-131018.zip',
ensure => file,
source => 'puppet:///modules/update_package/update-131018.zip',
before => Exec['update-131018']
}
exec { 'update-131018':
command => '/root/update-131018.sh',
}
执行exec的前提是:先有update-131018.sh及update-131018.zip两个文件,且update-131018.sh要有可执行权限;
客户端执行:
[root@mx /]# puppet agent -t
Info: Retrieving plugin
Info: Caching catalog for puppetclient1.com
Info: Applying configuration version '1383036536'
Notice: /Stage[main]//File[update-131018.sh]/ensure: defined content as '{md5}19e2d44448373148236f599270ebd485'
Notice: /Stage[main]//File[update-131018.zip]/ensure: defined content as '{md5}34d81766fd1a4c46f0b271df657ca5a3'
Notice: /Stage[main]//Exec[update-131018]/returns: executed successfully
Notice: Finished catalog run in 2.30 seconds