yundian 发表于 2013-4-8 09:08:30

puppet apache模块的例子

puppet apache模块的例子
[*]版本V1.0
[*]时间2013-04-07
[*]版权GPL
[*]作者itnihao
[*] 邮箱 itnihao@qq.com
[*]博客 http://itnihao.blog.
[*]如需重新发行,请注明以上信息,谢谢合作
一、apache模块的编写 目录结构/etc/puppet/modules/production/apache/
[*]├── files
[*]├── manifests
[*]│   ├── init.pp
[*]│   ├── install.pp
[*]│   ├── config.pp
[*]│   ├── serivce.pp
[*]│   └── vhost.pp
[*]└── templates
[*]    ├── http.conf.erb (httpd.conf文件改名的文件)
[*]    └── httpd.vhost.conf.erb
init.pp
=========================================================================

[*]class apache {
[*]​      include "apache::install", "apache::service","apache::core"
[*]}
[*]import 'install.pp'
[*]import 'config.pp'
[*]import 'serivce.pp'
[*]import 'vhost.pp'
========================================================================
install.pp
========================================================================

[*]class apache::install {
[*]    $ApacheVersion="2.2.15-15.el6.centos.1"   
[*]    package { "httpd":   
[*]      name   => $operatingsystem ? {   
[*]            /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ => "httpd",   
[*]            default    => "httpd",   
[*]            },   
[*]      ensure => $ApacheVersion,   
[*]    }   
========================================================================
config.pp
========================================================================


[*]class apache::core{
[*]file { 'httpd.conf':
[*]      path => $operatingsystem?{
[*]      /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ =>         "/etc/httpd/conf/httpd.conf",
[*]      default => "/etc/httpd/conf/httpd.conf",
[*]},
[*]      mode => 0600,
[*]      owner => root,
[*]      group => root,
[*]      content => template("apache/http.conf.erb"),
[*]      require => Class["apache::install"],
[*]      notify=> Class["apache::service"],
[*]      ensure=> present,
[*]      backup=> '.default',
[*]}
[*]}
=========================================================================
serivce.pp
=========================================================================

[*]class apache::service {
[*]    service { httpd:
[*]      name => $operatingsystem ? {
[*]            default => "httpd",
[*]               },
[*]      ensure => running,
[*]      enable => true,
[*]      hasrestart => true,
[*]      hasstatus => true,
[*]      require => Package["httpd"],
[*]      #subscribe => File["httpd.conf"],
[*]      subscribe => Class["apache::core"],
[*]            }
[*]}

=========================================================================
vhost.pp
========================================================================

[*]define apache::vhost($apacheport,$documentroot,$servername='') {
[*]      file {"$servername.conf ":
[*]            path => $operatingsystem ?{
[*]                /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ => "/etc/httpd/conf.d/${servername}.conf",
[*]                default => "/etc/httpd/conf.d/${servername}.conf",
[*]                },
[*]            mode => 0600,
[*]            owner => root,
[*]            group => root,
[*]            content => template("apache/httpd.vhost.conf.erb"),
[*]            require => Class["apache::core"],
[*]            notify=> Class["apache::service"],
[*]#            ensure=> present,
[*]#            backup=> '.default',
[*]         }
[*]}

=========================================================================
templates/httpd.vhost.conf.erb
========================================================================

[*]<VirtualHost *:<%=apacheport%>>
[*]    DocumentRoot <%=documentroot %>/<%= servername %>
[*]    ServerName <%= servername %>
[*]    ErrorLoglogs/<%= servername %>_error.log
[*]    CustomLog logs/<%= servername %>_access.log combined
[*]    DirectoryIndex index.htm index.html index.php
[*]    <Directory "<%=documentroot %>/<%= servername %>/">
[*]       options -followsymlinks -indexes -execcgi
[*]       AllowOverride None
[*]       Order deny,allow
[*]       Deny from all
[*]       Allow from 127.0.0.1
[*]</Directory>
[*]</VirtualHost>


=========================================================================
二、apache模块的应用
[*]node 'node1' {
[*]include apache
[*]apache::vhost { 'testport':
[*]               apacheport => 80,
[*]               documentroot => '/var/www/html',
[*]               servername => 'www.test.com',
[*]       }
[*]}
三、以上信息仅供参考,更多内容,请阅读官方文档

李斯特 发表于 2013-4-8 09:34:14

这是什么东东啊

超酷小 发表于 2013-5-16 14:17:36

路边的野花不要,踩。

上帝大脸 发表于 2013-5-17 22:13:18

hitl 发表于 2013-5-19 11:22:25

走,MM,咱们化蝶去……

314598340 发表于 2013-5-20 17:50:42

在一辆拥挤的公车上,一位女郎忽然叫了起来:别挤啦!别挤啦!把人家的奶都挤出来啦!(她拿着酸奶呢)。

remington_young 发表于 2013-5-22 02:39:32

如果有一双眼睛陪我一同哭泣,就值得我为生命受苦。
页: [1]
查看完整版本: puppet apache模块的例子