puppet apache模块的例子

一、apache模块的编写 

目录结构

/etc/puppet/modules/production/apache/

 
 
  1. ├── files 
  2. ├── manifests 
  3. │   ├── init.pp 
  4. │   ├── install.pp
  5. │   ├── config.pp
  6. │   ├── serivce.pp 
  7. │   └── vhost.pp 
  8. └── templates 
  9.     ├── http.conf.erb (httpd.conf文件改名的文件)
  10.     └── httpd.vhost.conf.erb 
init.pp
=========================================================================
 
 
  1. class apache { 
  2. ​      include "apache::install""apache::service","apache::core" 
  3. import 'install.pp' 
  4. import 'config.pp' 
  5. import 'serivce.pp' 
  6. import 'vhost.pp' 
========================================================================
install.pp
========================================================================
 
 
  1. class apache::install {  
  2.     $ApacheVersion="2.2.15-15.el6.centos.1"   
  3.     package { "httpd":   
  4.         name   => $operatingsystem ? {   
  5.             /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ => "httpd",   
  6.             default    => "httpd",   
  7.             },   
  8.         ensure => $ApacheVersion,   
  9.     }   
========================================================================
config.pp
========================================================================
 
 
 
  1. class apache::core
  2. file { 'httpd.conf'
  3.       path => $operatingsystem?{ 
  4.       /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ =>         "/etc/httpd/conf/httpd.conf"
  5.       default => "/etc/httpd/conf/httpd.conf"
  6. }, 
  7.       mode => 0600, 
  8.       owner => root, 
  9.       group => root, 
  10.       content => template("apache/http.conf.erb"), 
  11.       require => Class["apache::install"], 
  12.       notify  => Class["apache::service"], 
  13.       ensure=> present, 
  14.       backup  => '.default'
=========================================================================
serivce.pp
=========================================================================
 
 
  1. class apache::service { 
  2.     service { httpd: 
  3.         name => $operatingsystem ? { 
  4.             default => "httpd"
  5.                  }, 
  6.         ensure => running, 
  7.         enable => true
  8.         hasrestart => true
  9.         hasstatus => true
  10.         require => Package["httpd"], 
  11.         #subscribe => File["httpd.conf"], 
  12.         subscribe => Class["apache::core"], 
  13.             } 
=========================================================================
vhost.pp
========================================================================
 
 
  1. define apache::vhost($apacheport,$documentroot,$servername='') { 
  2.       file {"$servername.conf "
  3.             path => $operatingsystem ?{ 
  4.                 /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ => "/etc/httpd/conf.d/${servername}.conf"
  5.                 default => "/etc/httpd/conf.d/${servername}.conf"
  6.                 }, 
  7.             mode => 0600, 
  8.             owner => root, 
  9.             group => root, 
  10.             content => template("apache/httpd.vhost.conf.erb"), 
  11.             require => Class["apache::core"], 
  12.             notify  => Class["apache::service"], 
  13. #            ensure  => present, 
  14. #            backup  => '.default', 
  15.            } 
=========================================================================
templates/httpd.vhost.conf.erb 
========================================================================
 
 
  1. <VirtualHost *:<%=apacheport%>> 
  2.     DocumentRoot <%=  documentroot %>/<%= servername %> 
  3.     ServerName <%= servername %> 
  4.     ErrorLog  logs/<%= servername %>_error.log 
  5.     CustomLog logs/<%= servername %>_access.log combined 
  6.     DirectoryIndex index.htm index.html index.php 
  7.     <Directory "<%=  documentroot %>/<%= servername %>/"
  8.        options -followsymlinks -indexes -execcgi 
  9.        AllowOverride None 
  10.        Order deny,allow 
  11.        Deny from all 
  12.        Allow from 127.0.0.1 
  13.   </Directory> 
  14. </VirtualHost> 

=========================================================================

二、apache模块的应用

 
 
  1. node 'node1' {  
  2. include apache  
  3. apache::vhost { 'testport':  
  4.                apacheport => 80,  
  5.                documentroot => '/var/www/html',  
  6.                servername => 'www.test.com',  
  7.        }  

三、以上信息仅供参考,更多内容,请阅读官方文档



本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1172703,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值