Permalink
Browse files

Apache2 puppet module

  • Loading branch information...
1 parent a04ef9a commit 8a49f614600f75334b0325927814b7c1d73c3699 @deigote deigote committed May 24, 2012
View
28 README.md
@@ -1,4 +1,30 @@
puppet-apache2
==============
-Puppet module to manage apache2, with hability to enable or disable virtualhosts and modules
+Puppet module to manage apache2, with hability to enable or disable virtualhosts and modules. Examples:
+
+ class my_apache_conf {
+
+ apache2::module { "fastcgi":
+ modname => "fastcgi",
+ }
+
+ apache2::disable_virtualhost { "000-default":
+ conffile => "000-default",
+ }
+
+ apache2::proxy { "apache2-proxy-tomcat":
+ virtualhost_name => 'mytomcatapp.com',
+ server_admin_mail => 'admin@mytomcatapp.com',
+ backend_url => '127.0.0.1:8080'
+ }
+
+ apache2::redirection { "apache2-jenkins-redirect":
+ virtualhost_name => 'jenkins.myorg.com',
+ server_admin_mail => 'admin@myorg.com',
+ destination => 'http://continuos-integration.myorg.com/jenkins'
+ }
+ }
+
+For more advanced usages, you can check out the projects https://github.com/osoco/puppet-apache2_svn and https://github.com/osoco/puppet-apache2_trac
+
View
16 manifests/auth_digest.pp
@@ -0,0 +1,16 @@
+class apache2::auth_digest {
+
+ $module_suffix = "apache2_auth_digest"
+
+ apache2::module { "authz_host-$module_suffix":
+ modname => "authz_host",
+ }
+
+ apache2::module { "authn_file-$module_suffix":
+ modname => "authn_file",
+ }
+
+ apache2::module { "auth_digest-$module_suffix":
+ modname => "auth_digest",
+ }
+}
View
32 manifests/custom_virtualhost.pp
@@ -0,0 +1,32 @@
+define apache2::custom_virtualhost($conffile, $source = "", $content = "") {
+
+ include apache2
+
+ if ($source != "") {
+ file { "/etc/apache2/sites-available/$conffile":
+ owner => "root",
+ group => "root",
+ mode => "0640",
+ notify => Service["apache2"],
+ require => Package["apache2"],
+ source => "$source",
+ }
+ }
+ elsif ($content != "") {
+ file { "/etc/apache2/sites-available/$conffile":
+ owner => "root",
+ group => "root",
+ mode => "0640",
+ notify => Service["apache2"],
+ require => Package["apache2"],
+ content => "$content",
+ }
+ }
+
+ exec { "apache2-custom-virtualhost-$conffile":
+ command => "a2ensite $conffile",
+ creates => "/etc/apache2/sites-enabled/$conffile",
+ require => File["/etc/apache2/sites-available/$conffile"],
+ notify => Service["apache2"]
+ }
+}
View
10 manifests/disable_module.pp
@@ -0,0 +1,10 @@
+define apache2::disable_module($modname) {
+
+ include apache2
+
+ exec { "apache2-disable_module-$modname":
+ command => "a2dismod $modname",
+ onlyif => "test -f /etc/apache2/mods-enabled/$modname.load",
+ notify => Service["apache2"]
+ }
+}
View
10 manifests/disable_virtualhost.pp
@@ -0,0 +1,10 @@
+define apache2::disable_virtualhost($conffile) {
+
+ include apache2
+
+ exec { "apache2-disable-virtualhost-$conffile":
+ command => "a2dissite $conffile",
+ onlyif => "test -f /etc/apache2/sites-enabled/$conffile",
+ notify => Service["apache2"]
+ }
+}
View
15 manifests/init.pp
@@ -0,0 +1,15 @@
+class apache2 ($version = "latest") {
+
+ package { "apache2":
+ ensure => $version
+ }
+
+ service { "apache2":
+ ensure => running,
+ hasstatus => true,
+ hasrestart => true,
+ enable => true,
+ require => Package["apache2"]
+ }
+
+}
View
18 manifests/module.pp
@@ -0,0 +1,18 @@
+define apache2::module($modname) {
+
+ include apache2
+
+ file { "$modname-$name":
+ path => "/etc/apache2/mods-available/$modname.load",
+ owner => "root",
+ group => "root",
+ mode => 0640,
+ }
+
+ exec { "apache2-module-$modname-$name":
+ command => "a2enmod $modname",
+ creates => "/etc/apache2/mods-enabled/$modname.load",
+ require => File["/etc/apache2/mods-available/$modname.load"],
+ notify => Service["apache2"]
+ }
+}
View
13 manifests/proxy.pp
@@ -0,0 +1,13 @@
+define apache2::proxy($virtualhost_name, $server_admin_mail, $is_https = false, $ssl_cert = "", $ssl_cert_key = "",
+ $backend_url, $proxy_location = "/", proxy_type = "http", bypass_locations = []) {
+
+ apache2::module { "$virtualhost_name-proxy-$proxy_type-module":
+ modname => "proxy_${proxy_type}"
+ }
+
+ apache2::virtualhost { "$virtualhost_name":
+ virtualhost_name => "$virtualhost_name",
+ server_admin_mail => "$server_admin_mail",
+ virtualhost_specifics => template("apache2/proxy.erb")
+ }
+}
View
16 manifests/redirection.pp
@@ -0,0 +1,16 @@
+define apache2::redirection($virtualhost_name, $server_admin_mail, $is_https = false, $ssl_cert = "", $ssl_cert_key = "",
+ $origin = '/', $destination) {
+
+ if !defined(Apache2::Module["rewrite"])
+ {
+ apache2::module { "rewrite":
+ modname => "rewrite"
+ }
+ }
+
+ apache2::virtualhost { "$virtualhost_name":
+ virtualhost_name => "$virtualhost_name",
+ server_admin_mail => "$server_admin_mail",
+ virtualhost_specifics => template("apache2/redirection.erb")
+ }
+}
View
12 manifests/virtualhost.pp
@@ -0,0 +1,12 @@
+define apache2::virtualhost($virtualhost_name, $server_admin_mail, $document_root = "", $virtualhost_specifics = "",
+ $is_https = false, $ssl_cert = "", $ssl_cert_key = "", $rewrite_conds = []) {
+
+ include apache2
+
+ notify { "Apache2: Creating virtualhost $virtualhost_name with the conf: DocumentRoot '$document_root', IsHttps '$is_https', rewrite_conds '$rewrite_conds'": }
+
+ apache2::custom_virtualhost { "$virtualhost_name":
+ conffile => "$virtualhost_name",
+ content => template("apache2/virtual_host.erb")
+ }
+}
View
10 templates/proxy.erb
@@ -0,0 +1,10 @@
+ <Proxy *>
+ Order deny,allow
+ Allow from all
+ </Proxy>
+ ProxyPreserveHost On
+<% bypass_locations.each do |bypass_location| -%>
+ ProxyPass <%= bypass_location %> !
+<% end -%>
+ ProxyPass <%= proxy_location %> <%= proxy_type %>://<%= backend_url %><%= proxy_location %>
+ ProxyPassReverse <%= proxy_location %> <%= proxy_type %>://<%= backend_url %><%= proxy_location %>
View
3 templates/redirection.erb
@@ -0,0 +1,3 @@
+ RewriteEngine On
+ RewriteRule ^<%= origin %>$ <%= destination %> [L,R=301]
+ RewriteRule ^<%= origin %>(.*) <%= destination %>/$1 [L,R=301]
View
44 templates/virtual_host.erb
@@ -0,0 +1,44 @@
+<VirtualHost *:80>
+ ServerName <%= virtualhost_name %>
+<% if (server_admin_mail != "") -%>
+ ServerAdmin <%= server_admin_mail %>
+<% end -%>
+<% if (document_root != "") -%>
+ DocumentRoot <%= document_root %>
+<% end -%>
+
+<% if (is_https) -%>
+ RewriteEngine On
+ RewriteRule ^/$ https://<%= virtualhost_name %> [L,R=301]
+<% if (rewrite_conds != "") -%>
+ <%= rewrite_conds %>
+<% end -%>
+<% rewrite_conds do |rewrite_cond| -%>
+ <%= rewrite_cond %>
+<% end -%>
+ RewriteRule ^/(.*) https://<%= virtualhost_name %>/$1 [L,R=301]
+</VirtualHost>
+
+<VirtualHost *:443>
+ ServerName <%= virtualhost_name %>
+ <% if (server_admin_mail != "") -%>ServerAdmin <%= server_admin_mail %><% end %>
+<% if (document_root != "") -%>
+ DocumentRoot <%= document_root %>
+<% end -%>
+
+ SSLEngine On
+ SSLCertificateFile <%=ssl_cert%>
+<% if (ssl_cert_key != "") -%>
+ SSLCertificateKeyFile <%=ssl_cert_key%>
+<% end -%>
+<% end -%>
+
+<% if (virtualhost_specifics != "") -%>
+<%= virtualhost_specifics %>
+<% end -%>
+
+ ErrorLog ${APACHE_LOG_DIR}/<%= virtualhost_name %>_error.log
+ LogLevel warn
+ CustomLog ${APACHE_LOG_DIR}/<%= virtualhost_name %>_access.log combined
+</VirtualHost>
+

0 comments on commit 8a49f61

Please sign in to comment.