]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/horizon/manifests/wsgi/apache.pp
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / horizon / manifests / wsgi / apache.pp
1 # == Class: horizon::wsgi::apache
2 #
3 # Configures Apache WSGI for Horizon.
4 #
5 # === Parameters
6 #
7 #  [*bind_address*]
8 #    (optional) Bind address in Apache for Horizon. (Defaults to '0.0.0.0')
9 #
10 #  [*server_aliases*]
11 #    (optional) List of names which should be defined as ServerAlias directives
12 #    in vhost.conf.
13 #    Defaults to ::fqdn.
14 #
15 #  [*listen_ssl*]
16 #    (optional) Enable SSL support in Apache. (Defaults to false)
17 #
18 #  [*horizon_cert*]
19 #    (required with listen_ssl) Certificate to use for SSL support.
20 #
21 #  [*horizon_key*]
22 #    (required with listen_ssl) Private key to use for SSL support.
23 #
24 #  [*horizon_ca*]
25 #    (required with listen_ssl) CA certificate to use for SSL support.
26 #
27 #  [*wsgi_processes*]
28 #    (optional) Number of Horizon processes to spawn
29 #    Defaults to '3'
30 #
31 #  [*wsgi_threads*]
32 #    (optional) Number of thread to run in a Horizon process
33 #    Defaults to '10'
34 #
35 #  [*priority*]
36 #    (optional) The apache vhost priority.
37 #    Defaults to '15'. To set Horizon as the primary vhost, change to '10'.
38 #
39 #  [*extra_params*]
40 #    (optional) A hash of extra paramaters for apache::wsgi class.
41 #    Defaults to {}
42 class horizon::wsgi::apache (
43   $bind_address        = undef,
44   $fqdn                = undef,
45   $servername          = $::fqdn,
46   $server_aliases      = $::fqdn,
47   $listen_ssl          = false,
48   $ssl_redirect        = true,
49   $horizon_cert        = undef,
50   $horizon_key         = undef,
51   $horizon_ca          = undef,
52   $wsgi_processes      = '3',
53   $wsgi_threads        = '10',
54   $priority            = '15',
55   $vhost_conf_name     = 'horizon_vhost',
56   $vhost_ssl_conf_name = 'horizon_ssl_vhost',
57   $extra_params        = {},
58 ) {
59
60   include ::horizon::params
61   include ::apache
62
63   if $fqdn {
64     warning('Parameter fqdn is deprecated. Please use parameter server_aliases for setting ServerAlias directives in vhost.conf.')
65     $final_server_aliases = $fqdn
66   } else {
67     $final_server_aliases = $server_aliases
68   }
69
70   include ::apache::mod::wsgi
71
72   # We already use apache::vhost to generate our own
73   # configuration file, let's clean the configuration
74   # embedded within the package
75   file { $::horizon::params::httpd_config_file:
76     ensure  => present,
77     content => "#
78 # This file has been cleaned by Puppet.
79 #
80 # OpenStack Horizon configuration has been moved to:
81 # - ${priority}-${vhost_conf_name}.conf
82 # - ${priority}-${vhost_ssl_conf_name}.conf
83 #",
84     require => Package[$::horizon::params::package_name]
85   }
86
87
88   if $listen_ssl {
89     include ::apache::mod::ssl
90     $ensure_ssl_vhost = 'present'
91
92     if $horizon_ca == undef {
93       fail('The horizon_ca parameter is required when listen_ssl is true')
94     }
95
96     if $horizon_cert == undef {
97       fail('The horizon_cert parameter is required when listen_ssl is true')
98     }
99
100     if $horizon_key == undef {
101       fail('The horizon_key parameter is required when listen_ssl is true')
102     }
103
104     if $ssl_redirect {
105       $redirect_match = '(.*)'
106       $redirect_url   = "https://${servername}"
107     }
108
109   } else {
110     $ensure_ssl_vhost = 'absent'
111     $redirect_match = '^/$'
112     $redirect_url   = $::horizon::params::root_url
113   }
114
115   Package['horizon'] -> Package[$::horizon::params::http_service]
116   File[$::horizon::params::config_file] ~> Service[$::horizon::params::http_service]
117
118   $unix_user = $::osfamily ? {
119     'RedHat' => $::horizon::params::apache_user,
120     default  => $::horizon::params::wsgi_user
121   }
122   $unix_group = $::osfamily ? {
123     'RedHat' => $::horizon::params::apache_group,
124     default  => $::horizon::params::wsgi_group,
125   }
126
127   file { $::horizon::params::logdir:
128     ensure       => directory,
129     owner        => $unix_user,
130     group        => $unix_group,
131     before       => Service[$::horizon::params::http_service],
132     mode         => '0751',
133     require      => Package['horizon']
134   }
135
136   file { "${::horizon::params::logdir}/horizon.log":
137     ensure       => file,
138     owner        => $unix_user,
139     group        => $unix_group,
140     before       => Service[$::horizon::params::http_service],
141     mode         => '0640',
142     require      => [ File[$::horizon::params::logdir], Package['horizon'] ],
143   }
144
145   $default_vhost_conf_no_ip = {
146     servername           => $servername,
147     serveraliases        => os_any2array($final_server_aliases),
148     docroot              => '/var/www/',
149     access_log_file      => 'horizon_access.log',
150     error_log_file       => 'horizon_error.log',
151     priority             => $priority,
152     aliases              => [
153       { alias => '/static', path => '/usr/share/openstack-dashboard/static' }
154     ],
155     port                 => 80,
156     ssl_cert             => $horizon_cert,
157     ssl_key              => $horizon_key,
158     ssl_ca               => $horizon_ca,
159     wsgi_script_aliases  => hash([$::horizon::params::root_url, $::horizon::params::django_wsgi]),
160     wsgi_daemon_process  => $::horizon::params::wsgi_group,
161     wsgi_daemon_process_options => {
162       processes    => $wsgi_processes,
163       threads      => $wsgi_threads,
164       user         => $unix_user,
165       group        => $unix_group,
166     },
167     wsgi_import_script   => $::horizon::params::django_wsgi,
168     wsgi_process_group   => $::horizon::params::wsgi_group,
169     redirectmatch_status => 'permanent',
170   }
171
172   # Only add the 'ip' element to the $default_vhost_conf hash if it was explicitly
173   # specified in the instantiation of the class.  This is because ip => undef gets
174   # changed to ip => '' via the Puppet function API when ensure_resource is called.
175   # See https://bugs.launchpad.net/puppet-horizon/+bug/1371345
176   if $bind_address {
177     $default_vhost_conf = merge($default_vhost_conf_no_ip, { ip => $bind_address })
178   } else {
179     $default_vhost_conf = $default_vhost_conf_no_ip
180   }
181
182   ensure_resource('apache::vhost', $vhost_conf_name, merge ($default_vhost_conf, $extra_params, {
183     redirectmatch_regexp => $redirect_match,
184     redirectmatch_dest   => $redirect_url,
185   }))
186   ensure_resource('apache::vhost', $vhost_ssl_conf_name, merge ($default_vhost_conf, $extra_params, {
187     access_log_file      => 'horizon_ssl_access.log',
188     error_log_file       => 'horizon_ssl_error.log',
189     priority             => $priority,
190     ssl                  => true,
191     port                 => 443,
192     ensure               => $ensure_ssl_vhost,
193     wsgi_daemon_process  => 'horizon-ssl',
194     wsgi_process_group   => 'horizon-ssl',
195     redirectmatch_regexp => '^/$',
196     redirectmatch_dest   => $::horizon::params::root_url,
197   }))
198
199 }