Skip to content

Instantly share code, notes, and snippets.

@robperc
Last active March 2, 2016 18:50
Show Gist options
  • Save robperc/981699ecec9414428370 to your computer and use it in GitHub Desktop.
Save robperc/981699ecec9414428370 to your computer and use it in GitHub Desktop.
Apache Puppet Module using Puppet's best practice standards and architecture.
Apache Puppet Module using Puppet's best practice standards and architecture.
class apache::config inherits apache {
file { $index:
ensure => file,
owner => 0,
group => 0,
mode => '0644',
source => $config_template,
}
}
<html>
<head>
<title>Hello, World</title>
</head>
<body>
<h1>Hello, World</h1>
</body>
</html>
class apache (
$package_ensure = $apache::params::package_ensure,
$package_name = $apache::params::package_name,
$index = $apache::params::index,
$index_template = $apache::params::index_template,
$service_ensure = $apache::params::service_ensure,
$service_enable = $apache::params::service_enable,
$service_manage = $apache::params::service_manage,
$service_name = $apache::params::service_name
) inherits apache::params {
contain apache::install
contain apache::config
contain apache::service
anchor { 'apache_begin': }
anchor { 'apache_end': }
Anchor['apache_begin'] ->
Class['apache::install'] ~>
Class['apache::config'] ~>
Class['apache::service'] ->
Anchor['apache_end']
}
class apache::install inherits apache {
package {'apache':
ensure => $package_ensure,
name => $package_name,
}
}
class apache::params {
case $::osfamily {
'Debian': {
$package_name = "apache2"
$service_name = "apache2"
}
'RedHat': {
$package_name = "httpd"
$service_name = "httpd"
}
}
$index = '/var/www/html/index.html'
$index_template = 'puppet:///modules/apache/index.html'
$package_ensure = present
$service_ensure = running
$service_enable = true
$service_manage = true
}
class apache::service inherits apache {
if ! ($service_ensure in [ 'running', 'stopped' ]) {
fail('service_ensure parameter must be running or stopped')
}
if $service_manage == true {
service { 'apache':
ensure => $service_ensure,
enable => $service_enable,
name => $service_name,
hasstatus => true,
hasrestart => true,
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment