Skip to content

Instantly share code, notes, and snippets.

@thsutton
Created February 21, 2011 08:10
Show Gist options
  • Save thsutton/836800 to your computer and use it in GitHub Desktop.
Save thsutton/836800 to your computer and use it in GitHub Desktop.
# modules/apache/manifests/init.pp
#
# Configure and manage Apache (in the Debian manner).
#
class apache {
# Configuration that might need to be tweaked.
$apache2_mods = "/etc/apache2/mods"
$apache2_sites = "/etc/apache2/sites"
package { "apache2":
ensure => "installed",
}
service { "apache2":
enable => "true",
ensure => "running",
hasrestart => "true",
hasstatus => "true",
require => Package["apache2"],
}
exec { "reload-apache2":
command => "/etc/init.d/apache2 reload",
refreshonly => true,
}
exec { "force-reload-apache2":
command => "/etc/init.d/apache2 force-reload",
refreshonly => true,
}
site { "default":
ensure => "absent"
}
site { "default-ssl":
ensure => "absent"
}
#
# Install and/or enable Apache modules.
#
define module ($ensure = "present") {
case $ensure {
"present" : {
exec { "/usr/sbin/a2enmod $name":
#unless => "/bin/readlink -e /etc/apache2/mods-enabled/${name}.load",
unless => "/bin/readlink -e ${apache2_mods}-enabled/${name}.load",
notify => Exec["force-reload-apache2"],
require => Package["apache2"],
}
} #present
"absent": {
exec { "/usr/sbin/a2dismod $name":
#onlyif => "/bin/readlink -e /etc/apache2/mods-enabled/${name}.load",
onlyif => "/bin/readlink -e ${apache2_mods}-enabled/${name}.load",
notify => Exec["force-reload-apache2"],
require => Package["apache2"],
}
} #absent
default: {
err ("Unknown ensure value for apache::module '$ensure'")
} #default
}
}
#
# Enable and/or disable Apache sites.
#
define site ($ensure = 'present') {
case $ensure {
"present" : {
exec { "/usr/sbin/a2ensite $name" :
unless => "/bin/readlink -e ${apache2_sites}-enabled/$name",
notify => Exec["reload-apache2"],
require => Package[$require],
}
} # present
"absent" : {
exec { "/usr/sbin/a2dissite $name" :
onlyif => "/bin/readlink -e ${apache2_sites}-enabled/$name",
notify => Exec["reload-apache2"],
require => Package["apache2"],
}
} # absent
default : {
err ("Unknown ensure value for apache::site '$ensure")
} # default
}
} # define site
} # class apache
@thsutton
Copy link
Author

This puppet manifest is only lightly modified from the Debian Apache pattern described on the Puppet Labs wiki. For some (likely stupid) reason apache::site works fine (i.e. the unless and ifonly checks substitute in the variable names) but apache::module runs the command and restarts the server every time puppet is invoked (because the value of ${apache_mods} is not substituted in).

Executing check '/bin/readlink -e /etc/apache2/sites-enabled/default-ssl'

...

Executing check '/bin/readlink -e -enabled/rewrite.load'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment