50010623 发表于 2018-8-3 07:25:53

puppet apache模块的例子

  puppet apache模块的例子
  


[*]版本V1.0
[*]时间2013-04-07
[*]版权GPL
[*]作者itnihao
[*] 邮箱 itnihao@qq.com
[*]博客 http://itnihao.blog.51cto.com
[*]如需重新发行,请注明以上信息,谢谢合作
  

  一、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 &quot;<%=documentroot %>/<%= servername %>/&quot;>
[*]       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',
[*]       }
[*]}
  

  三、以上信息仅供参考,更多内容,请阅读官方文档
页: [1]
查看完整版本: puppet apache模块的例子