Giuseppe Lavagetto has uploaded a new change for review. https://gerrit.wikimedia.org/r/151605
Change subject: apache: adding apache::mod_files ...................................................................... apache: adding apache::mod_files Apache modules may often need some config files, that need to be realized before we enable the module, a good example is what we do in the mediawiki module. This define allows to define content of both the modulename.load file and of the modulename.conf file. Both are declared as virtual resources that will be realized by the corresponding apache::mod_conf resource if declared. Also, we remove the 'creates' clause from apache2::mod_conf as running a2enmod is harmless and idempotent anyway, and doing so ensures we can safely move between states. Change-Id: Ided794308c5a5a02c6c6c6c5cf7c6045ff0319b8 Signed-off-by: Giuseppe Lavagetto <glavage...@wikimedia.org> --- M modules/apache/manifests/mod_conf.pp A modules/apache/manifests/mod_files.pp M modules/apache/manifests/mpm.pp 3 files changed, 110 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/05/151605/1 diff --git a/modules/apache/manifests/mod_conf.pp b/modules/apache/manifests/mod_conf.pp index 0973c43..ab52900 100644 --- a/modules/apache/manifests/mod_conf.pp +++ b/modules/apache/manifests/mod_conf.pp @@ -16,17 +16,38 @@ # The .load config file that Puppet should manage. # Defaults to the resource title plus a '.load' suffix. # +# [*conffile*] +# The .conf config file that Puppet should manage. +# Defaults to the resource title plus a '.conf' suffix. +# + define apache::mod_conf( $ensure = present, $mod = $title, $loadfile = "${title}.load", -) { + $conffile = "${title}.conf", + ) { include ::apache + $loadfile_path = "/etc/apache2/mods-available/${loadfile}" + $conffile_path = "/etc/apache2/mods-available/${conffile}" + + $loadfile_target = "/etc/apache2/mods-enabled/${loadfile}" + $conffile_path = "/etc/apache2/mods-enabled/${conffile}" + + # Make sure all resources are in place + File<| path == $loadfile_path or path == $conffile_path |> + + # Edge case: we're adding a .conf file to a resource that's already + # been enabled. So given a2enmod is a very simple, idempotent + # shell script we can safely exec it at every puppet run. + # a2enmod will then do the right thing(TM). + # OTOH, when we run a2dismod it's enough to be sure we removed the + # loadfile as it will effectively remove the module from the + # apache configuration. if $ensure == present { exec { "ensure_${ensure}_mod_${mod}": command => "/usr/sbin/a2enmod ${mod}", - creates => "/etc/apache2/mods-enabled/${loadfile}", require => Package['apache2'], notify => Service['apache2'], } diff --git a/modules/apache/manifests/mod_files.pp b/modules/apache/manifests/mod_files.pp new file mode 100644 index 0000000..a482d74 --- /dev/null +++ b/modules/apache/manifests/mod_files.pp @@ -0,0 +1,83 @@ +# == Define: apache::mod_files +# +# Custom resource form managing config files for apache modules. +# +# This define completes the apache::mod_conf define and allows you to +# override the existing, distribution provided config files for your +# modules. +# Note that when not absented, this resource will only define virtual +# file resources that will be realized by the corresponding +# apache::mod_conf or, at higher level, by the corresponding +# apache::mpm or apache::mod::<module> classes. +# +# === Parameters +# +# [*conf_source*] +# Source file for the .conf module config file +# +# [*load_source*] +# Same thing for the load file +# +# [*conf_content*] +# Content for the .conf module config file +# +# [*load_content*] +# Same thing for the load file +# + +define apache::mod_files( + $ensure = 'present', + $conf_source = undef, + $conf_content = undef, + $load_source = undef, + $load_content = undef, +){ + $load_file = "/etc/apache2/mods_available/${title}.load" + $conf_file = "/etc/apache2/mods_available/${title}.conf" + # Not that ensure == 'absent' is *really* a corner-case as most + # modules configs are taken care of by the corresponding debian + # package. There may be cases where we added manually a config and + # we want to remove it for tidiness. + # + if $ensure == 'absent' { + file { [$conf_file, $load_file]: + ensure => absent, + } + } else { + # Safeguards + if $load_source != undef and $load_content != undef { fail('"source" and "content" are mutually exclusive') } + if $conf_source != undef and $conf_content != undef { fail('"source" and "content" are mutually exclusive') } + + # Virtual resource, will be realized when the corresponding + # mod_conf gets declared. + if ($load_source != undef or $load_content != undef) { + @file { $load_file: + ensure => present, + content => $load_content, + source => $load_source, + owner => 'root', + group => 'root', + mode => '0444', + } + } else { + # We need this file to be defined anyways, even if empty + # See mpm_* config on precise + @file { $load_file: + ensure => present, + owner => 'root', + group => 'root', + mode => '0444', + } + } + if ($conf_source != undef or $conf_content != undef) { + @file { $conf_file: + ensure => present, + content => $conf_content, + source => $conf_source, + owner => 'root', + group => 'root', + mode => '0444', + } + } + } +} diff --git a/modules/apache/manifests/mpm.pp b/modules/apache/manifests/mpm.pp index 6808b52..4064e25 100644 --- a/modules/apache/manifests/mpm.pp +++ b/modules/apache/manifests/mpm.pp @@ -16,7 +16,7 @@ # Name of the chosen MPM. Must be 'prefork', 'worker', or 'event'. # The default is 'prefork'. # -class apache::mpm( $mpm = 'prefork' ) { +class apache::mpm( $mpm = 'prefork', $config = undef) { include ::apache $available_mpms = ['prefork', 'worker', 'event'] @@ -26,7 +26,6 @@ $selected_mod = "mpm_${mpm}" $selected_pkg = "apache2-mpm-${mpm}" - $selected_cfg = "/etc/apache2/mods-available/mpm_${mpm}.load" $rejected_mpms = reject($available_mpms, $mpm) $rejected_mods = prefix($rejected_mpms, 'mpm_') @@ -47,16 +46,12 @@ if ubuntu_version('< trusty') { package { $selected_pkg: ensure => present, - before => File[$selected_cfg], + before => Apache::Mod_files[$selected_mod], } } - file { $selected_cfg: - ensure => file, - owner => 'root', - group => 'root', - mode => '0444', - before => Apache::Mod_conf[$selected_mod], + apache::mod_files { $selected_mod: + config_content => $config } apache::mod_conf { $selected_mod: -- To view, visit https://gerrit.wikimedia.org/r/151605 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ided794308c5a5a02c6c6c6c5cf7c6045ff0319b8 Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits