From: Peter Palfrader Date: Mon, 21 Oct 2019 09:27:19 +0000 (+0200) Subject: Clean up and document apache2::site X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fdsa-puppet.git;a=commitdiff_plain;h=3c3550e7e0f4e90f4af39467dd2a991008dfaece Clean up and document apache2::site --- diff --git a/modules/apache2/manifests/site.pp b/modules/apache2/manifests/site.pp index 1a71e09d4..b847c223e 100644 --- a/modules/apache2/manifests/site.pp +++ b/modules/apache2/manifests/site.pp @@ -1,68 +1,40 @@ +# Install and enable an apache site +# +# @param source source of the apache vhost file +# @param content content of the apache vhost file +# @param ensure present or absent +# @param site site name define apache2::site ( - $source=undef, - $content=undef, - $ensure=present, - $site=undef + Optional[String] $source = undef, + Optional[String] $content = undef, + Enum['present','absent'] $ensure = 'present', + String $site = $name ) { - include apache2 - case $ensure { - present: { - if ! ($source or $content) { - fail ( "No configuration found for ${name}" ) - } - } - absent: {} - default: { fail ( "Unknown ensure value: '$ensure'" ) } - } - - if $site { - $base = $site - } else { - $base = $name - } - - $target = "/etc/apache2/sites-available/${base}" - - $link_target = $ensure ? { - present => $target, - absent => absent - } - - if $content { - file { $target: - ensure => $ensure, - content => $content, - require => Package['apache2'], - notify => Exec['service apache2 reload'], - } - } else { - file { $target: - ensure => $ensure, - source => $source, - require => Package['apache2'], - notify => Exec['service apache2 reload'], + if $ensure == 'present' { + if ! ($source or $content) { + fail ( "No configuration (source or content) found for ${name}" ) } } + $target = "/etc/apache2/sites-available/${site}" $symlink = "/etc/apache2/sites-enabled/${name}.conf" + $link_ensure = $ensure ? { + present => link, + absent => absent, + } - file { "/etc/apache2/sites-enabled/${name}": - ensure => absent, + file { $target: + ensure => $ensure, + content => $content, + source => $source, + require => Package['apache2'], notify => Exec['service apache2 reload'], } - - if $ensure == present { - file { $symlink: - ensure => link, - target => $link_target, - notify => Exec['service apache2 reload'], - } - } else { - file { $symlink: - ensure => absent, - notify => Exec['service apache2 reload'], - } + file { $symlink: + ensure => $link_ensure, + target => $target, + notify => Exec['service apache2 reload'], } }