puppet code module class task

Posted 芒果牛奶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了puppet code module class task相关的知识,希望对你有一定的参考价值。

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,
     }
}

以上是关于puppet code module class task的主要内容,如果未能解决你的问题,请参考以下文章

Puppeteer 类型 node_modules/puppeteer/lib/types"' 没有导出成员 'Cookie'

如何做好Puppet Modules管理

Puppet module命令参数介绍

puppet 详细使用module模块配置ubuntu local repository

puppet(单机模式)-基于模块方式实现redis主从

puppet 搭建lnmp架构