Defined Type: apache::virtualhost

Defined in:
manifests/virtualhost.pp

Overview

Define: apache::virtualhost

NOTE: This define does the same function of apache::vhost and is

now deprecated. Use apache::vhost instead.

Basic Virtual host management define You can use different templates for your apache virtual host files Default is virtualhost.conf.erb, adapt it to your needs or create your custom template.

Usage:

With standard template: apache::virtualhost { “www.example42.com”: }

With custom template (create it in MODULEPATH/apache/templates/virtualhost/) apache::virtualhost { “webmail.example42.com”:

templatefile => "webmail.conf.erb"

}

With custom template in custom location (MODULEPATH/mymod/templates/apache/vihost/) apache::virtualhost { “webmail.example42.com”:

templatefile => "webmail.conf.erb"
templatepath => "mymod/apache/vihost"

}

Parameters:

  • templatefile (Any) (defaults to: 'virtualhost.conf.erb')
  • templatepath (Any) (defaults to: 'apache/virtualhost')
  • documentroot (Any) (defaults to: '')
  • filename (Any) (defaults to: '')
  • aliases (Any) (defaults to: '')
  • create_docroot (Any) (defaults to: true)
  • enable (Any) (defaults to: true)
  • owner (Any) (defaults to: '')
  • content (Any) (defaults to: '')
  • groupowner (Any) (defaults to: '')


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'manifests/virtualhost.pp', line 27

define apache::virtualhost (
  $templatefile   = 'virtualhost.conf.erb' ,
  $templatepath   = 'apache/virtualhost' ,
  $documentroot   = '' ,
  $filename       = '' ,
  $aliases        = '' ,
  $create_docroot = true ,
  $enable         = true ,
  $owner          = '' ,
  $content        = '' ,
  $groupowner     = '' ) {

  include apache

  $real_filename = $filename ? {
    ''      => $name,
    default => $filename,
  }

  $real_documentroot = $documentroot ? {
    ''      =>  "${apache::data_dir}/${name}",
    default => $documentroot,
  }

  $real_owner = $owner ? {
        ''      => $apache::config_file_owner,
        default => $owner,
  }

  $real_groupowner = $groupowner ? {
        ''      => $apache::config_file_group,
        default => $groupowner,
}

  $real_path = $::operatingsystem ? {
    /(?i:Debian|Ubuntu|Mint)/ => "${apache::vdir}/${real_filename}",
    default                   => "${apache::vdir}/${real_filename}.conf",
  }

  $ensure_link = any2bool($enable) ? {
    true  => "${apache::vdir}/${real_filename}",
    false => absent,
  }
  $ensure = bool2ensure($enable)
  $bool_create_docroot = any2bool($enable) ? {
    true  => any2bool($create_docroot),
    false => false,
  }

  $real_content = $content ? {
    ''      => template("${templatepath}/${templatefile}"),
    default => $content,
  }

  file { "ApacheVirtualHost_${name}":
    ensure  => $ensure,
    path    => $real_path,
    content => $real_content,
    mode    => $apache::config_file_mode,
    owner   => $apache::config_file_owner,
    group   => $apache::config_file_group,
    require => Package['apache'],
    notify  => $apache::manage_service_autorestart,
  }

  # Some OS specific settings:
  # On Debian/Ubuntu manages sites-enabled
  case $::operatingsystem {
    ubuntu,debian,mint: {
      file { "ApacheVirtualHostEnabled_${name}":
        ensure  => $ensure_link,
        path    => "${apache::config_dir}/sites-enabled/${real_filename}",
        require => Package['apache'],
      }
    }
    redhat,centos,scientific,fedora: {
      include apache::redhat
    }
    default: { }
  }

  if $bool_create_docroot == true {
    file { $real_documentroot:
      ensure => directory,
      owner  => $real_owner,
      group  => $real_groupowner,
      mode   => '0775',
    }
  }

}