1、type name parameters properties
puppet describe --list
puppet describe package -s -m
puppet describe package -m
resource Service[“puppet"]
(type) (name)
service { ‘puppet’:
(parameter) (property)
ensure => ’stopped’,
(parameter) (property)
provider => ‘upstart'
}
对于每一个属性,puppet会执行以下的任务
1、测试资源是否已经与目标状态同步
2、如果资源不同步,则会触发同步操作
2、执行测试你的manifest
puppet apply site.pp
puppet apply -e 'service { “puppet”: enable => true }'
测试语法不执行
puppet apply site.pp —noop
查看模块路径
puppet module list
查看类型应用
puppet describe <type>
3、变量
class apache {
$httppackets = ['httpd','php56u' ,'php56u-cli' ,'php56u-mysql' ,'php56u-mbstring' ,'php56u-mcrypt' ,'php56u-xml' ,'php56u-xmlrpc' ,'php56u-intl' ,'php56u-pecl-jsonc' ,'php56u-pecl-memcache' ,'php56u-pecl-memcached','php56u-bcmath' ,'php56u-gd' ,'php56u-opcache' ,'php56u-pecl-redis' ,'mod_ssl']
package { $httppackets:
ensure => 'installed',
}
}
4、依赖
package { 'haproxy':
ensure => 'installed',
}
->
file { '/etc/haproxy/haproxy.cfg':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/haproxy/etc/haproxy/haproxy.cfg',
}
->
service {'haproxy':
ensure => 'running',
}
package { 'haproxy':
ensure => 'installed',
}
file {'/etc/haproxy/haproxy.cfg':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/haproxy/etc/haproxy/haproxy.cfg',
require => Package['haproxy'],
}
service {'haproxy':
ensure => 'running',
require => File['/etc/haproxy/haproxy.cfg'],
}
package { 'haproxy':
ensure => 'installed',
before => File['/etc/haproxy/haproxy.cfg'],
}
file { '/etc/haproxy/haproxy.cfg':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/haproxy/etc/haproxy/haproxy.cfg', before => Service['haproxy'],
}
service { 'haproxy':
ensure => 'running',
}
当依赖执行不成功,后面的依赖的resource都不会执行
service { 'count-logins':
provider => 'base',
ensure => 'running',
enable => true,
binary => '/usr/local/bin/cnt-logins',
start => '/usr/local/bin/cnt-logins –daemonize',
has_status => true,
has_restart => true,
subscribe => File['/usr/local/bin/cnt-logins'],
}
不运行时,会重新启动,配置文件属性更改时,也会重新启动
exec { 'echo "test" >> haha.txt':
cwd => '/tmp',
creates => '/tmp/haha.txt',
path => ['/bin','/usr/bin','/usr/sbin'],
}
path是环境变量,creates判定文件是否存在,返回false则执行exec
资源调用
# A multi-resource reference:
require => File['/etc/apache2/httpd.conf', '/etc/apache2/magic', '/etc/apache2/mime.types'],
# An equivalent multi-resource reference:
$my_files = ['/etc/apache2/httpd.conf', '/etc/apache2/magic', '/etc/apache2/mime.types']
require => File[$my_files]
puppet class结构
Class { ‘apache’:
default_vhost => true,
}
Class { 'apache::vhost’:
user.example.com’ => {
port => 80,
docroot => /var/www/html/,
}
class apache {
$httppackets = ['httpd','php56u' ,'php56u-cli' ,'php56u-mysql' ,'php56u-mbstring' ,'php56u-mcrypt' ,'php56u-xml' ,'php56u-xmlrpc' ,'php56u-intl' ,'php56u-pecl-jsonc' ,'php56u-pecl-memcache' ,'php56u-pecl-memcached','php56u-bcmath' ,'php56u-gd' ,'php56u-opcache' ,'php56u-pecl-redis' ,'mod_ssl']
package { $httppackets:
ensure => 'installed',
}
}
为某台机器定义一张清单
node ‘agent_name' {
$packages = [ 'apache2', 'libapache2-mod-php5', 'libapache2-mod-passenger', ]
package { $packages:
ensure => 'installed',
before => Service['apache2'],
}
service { 'apache2':
ensure => 'running',
enable => true,
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。