一、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 %>
- ErrorLog logs/<%= 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',
- }
- }
三、以上信息仅供参考,更多内容,请阅读官方文档
本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1172703,如需转载请自行联系原作者