X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fapache2%2Fmanifests%2Fsite.pp;h=b847c223e4455b5a2bc67b9a1984d0f7160b9496;hb=4bcc03b6b6893ed1f6cddc277930cc48756b40a3;hp=6d5ec55f3357ac59b442f573a9139dadb6e8b564;hpb=4b0d5b04319abfcdd5ef3a80b31f7728900f358e;p=mirror%2Fdsa-puppet.git diff --git a/modules/apache2/manifests/site.pp b/modules/apache2/manifests/site.pp index 6d5ec55f3..b847c223e 100644 --- a/modules/apache2/manifests/site.pp +++ b/modules/apache2/manifests/site.pp @@ -1,72 +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 versioncmp($::lsbmajdistrelease, '7') <= 0 { - $symlink = "/etc/apache2/sites-enabled/${name}" - } else { - $symlink = "/etc/apache2/sites-enabled/${name}.conf" - - file { "/etc/apache2/sites-enabled/${name}": - ensure => absent, - 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'], - } - } + include apache2 + + 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 { $target: + ensure => $ensure, + content => $content, + source => $source, + require => Package['apache2'], + notify => Exec['service apache2 reload'], + } + file { $symlink: + ensure => $link_ensure, + target => $target, + notify => Exec['service apache2 reload'], + } }