Make heat auth_encryption_key random
[apex-tripleo-heat-templates.git] / puppet / manifests / loadbalancer.pp
1 # Copyright 2014 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 if !str2bool(hiera('enable_package_install', 'false')) {
17   case $::osfamily {
18     'RedHat': {
19       Package { provider => 'norpm' } # provided by tripleo-puppet
20     }
21     default: {
22       warning('enable_package_install option not supported.')
23     }
24   }
25 }
26
27 class tripleo::loadbalancer (
28   $keystone_admin     = false,
29   $keystone_public    = false,
30   $neutron            = false,
31   $cinder             = false,
32   $glance_api         = false,
33   $glance_registry    = false,
34   $nova_ec2           = false,
35   $nova_osapi         = false,
36   $nova_metadata      = false,
37   $nova_novncproxy    = false,
38   $ceilometer         = false,
39   $swift_proxy_server = false,
40   $heat_api           = false,
41   $heat_cloudwatch    = false,
42   $heat_cfn           = false,
43   $horizon            = false,
44   $mysql              = false,
45   $rabbitmq           = false,
46 ) {
47
48   case $::osfamily {
49     'RedHat': {
50       $keepalived_name_is_process = false
51       $keepalived_vrrp_script     = 'systemctl status haproxy.service'
52     } # RedHat
53     'Debian': {
54       $keepalived_name_is_process = true
55       $keepalived_vrrp_script     = undef
56     }
57   }
58
59   class { 'keepalived': }
60   keepalived::vrrp_script { 'haproxy':
61     name_is_process => $keepalived_name_is_process,
62     script          => $keepalived_vrrp_script,
63   }
64
65   # KEEPALIVE INSTANCE CONTROL
66   keepalived::instance { '51':
67     interface     => hiera('control_virtual_interface'),
68     virtual_ips   => [join([hiera('controller_virtual_ip'), ' dev ', hiera('control_virtual_interface')])],
69     state         => 'MASTER',
70     track_script  => ['haproxy'],
71     priority      => 101,
72   }
73
74   # KEEPALIVE INSTANCE PUBLIC
75   keepalived::instance { '52':
76     interface     => hiera('public_virtual_interface'),
77     virtual_ips   => [join([hiera('public_virtual_ip'), ' dev ', hiera('public_virtual_interface')])],
78     state         => 'MASTER',
79     track_script  => ['haproxy'],
80     priority      => 101,
81   }
82
83   sysctl::value { 'net.ipv4.ip_nonlocal_bind': value => '1' }
84
85   class { 'haproxy':
86     global_options   => {
87       'log'     => '/dev/log local0',
88       'pidfile' => '/var/run/haproxy.pid',
89       'user'    => 'haproxy',
90       'group'   => 'haproxy',
91       'daemon'  => '',
92       'maxconn' => '4000',
93     },
94     defaults_options => {
95       'mode'    => 'tcp',
96       'log'     => 'global',
97       'retries' => '3',
98       'maxconn' => '150',
99       'option'  => [ 'tcpka', 'tcplog' ],
100       'timeout' => [ 'http-request 10s', 'queue 1m', 'connect 10s', 'client 1m', 'server 1m', 'check 10s' ],
101     },
102   }
103
104   haproxy::listen { 'haproxy.stats':
105     ipaddress        => '*',
106     ports            => '1993',
107     mode             => 'http',
108     options          => {
109       'stats' => 'enable',
110     },
111     collect_exported => false,
112   }
113
114   if $keystone_admin {
115     haproxy::listen { 'keystone_admin':
116       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
117       ports            => 35357,
118       options          => { 'option' => [ 'httpchk GET /' ] },
119       collect_exported => false,
120     }
121     haproxy::balancermember { 'keystone_admin':
122       listening_service => 'keystone_admin',
123       ports             => '35357',
124       ipaddresses       => hiera('controller_host'),
125       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
126     }
127   }
128
129   if $keystone_public {
130     haproxy::listen { 'keystone_public':
131       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
132       ports            => 5000,
133       options          => { 'option' => [ 'httpchk GET /' ] },
134       collect_exported => false,
135     }
136     haproxy::balancermember { 'keystone_public':
137       listening_service => 'keystone_public',
138       ports             => '5000',
139       ipaddresses       => hiera('controller_host'),
140       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
141     }
142   }
143
144   if $neutron {
145     haproxy::listen { 'neutron':
146       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
147       ports            => 9696,
148       options          => { 'option' => [ 'httpchk GET /' ] },
149       collect_exported => false,
150     }
151     haproxy::balancermember { 'neutron':
152       listening_service => 'neutron',
153       ports             => '9696',
154       ipaddresses       => hiera('controller_host'),
155       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
156     }
157   }
158
159   if $cinder {
160     haproxy::listen { 'cinder':
161       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
162       ports            => 8776,
163       options          => { 'option' => [ 'httpchk GET /' ] },
164       collect_exported => false,
165     }
166     haproxy::balancermember { 'cinder':
167       listening_service => 'cinder',
168       ports             => '8776',
169       ipaddresses       => hiera('controller_host'),
170       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
171     }
172   }
173
174   if $glance_api {
175     haproxy::listen { 'glance_api':
176       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
177       ports            => 9292,
178       options          => { 'option' => [ 'httpchk GET /' ] },
179       collect_exported => false,
180     }
181     haproxy::balancermember { 'glance_api':
182       listening_service => 'glance_api',
183       ports             => '9292',
184       ipaddresses       => hiera('controller_host'),
185       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
186     }
187   }
188
189
190   if $glance_registry {
191     haproxy::listen { 'glance_registry':
192       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
193       ports            => 9191,
194       options          => { 'option' => [ 'httpchk GET /' ] },
195       collect_exported => false,
196     }
197     haproxy::balancermember { 'glance_registry':
198       listening_service => 'glance_registry',
199       ports             => '9191',
200       ipaddresses       => hiera('controller_host'),
201       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
202     }
203   }
204
205   if $nova_ec2 {
206     haproxy::listen { 'nova_ec2':
207       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
208       ports            => 8773,
209       options          => { 'option' => [ 'httpchk GET /' ] },
210       collect_exported => false,
211     }
212     haproxy::balancermember { 'nova_ec2':
213       listening_service => 'nova_ec2',
214       ports             => '8773',
215       ipaddresses       => hiera('controller_host'),
216       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
217     }
218   }
219
220   if $nova_osapi {
221     haproxy::listen { 'nova_osapi':
222       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
223       ports            => 8774,
224       options          => { 'option' => [ 'httpchk GET /' ] },
225       collect_exported => false,
226     }
227     haproxy::balancermember { 'nova_osapi':
228       listening_service => 'nova_osapi',
229       ports             => '8774',
230       ipaddresses       => hiera('controller_host'),
231       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
232     }
233   }
234
235   if $nova_metadata {
236     haproxy::listen { 'nova_metadata':
237       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
238       ports            => 8775,
239       options          => { 'option' => [ 'httpchk GET /' ] },
240       collect_exported => false,
241     }
242     haproxy::balancermember { 'nova_metadata':
243       listening_service => 'nova_metadata',
244       ports             => '8775',
245       ipaddresses       => hiera('controller_host'),
246       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
247     }
248   }
249
250   if $nova_novncproxy {
251     haproxy::listen { 'nova_novncproxy':
252       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
253       ports            => 6080,
254       options          => { 'option' => [ 'httpchk GET /' ] },
255       collect_exported => false,
256     }
257     haproxy::balancermember { 'nova_novncproxy':
258       listening_service => 'nova_novncproxy',
259       ports             => '6080',
260       ipaddresses       => hiera('controller_host'),
261       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
262     }
263   }
264
265   if $ceilometer {
266     haproxy::listen { 'ceilometer':
267       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
268       ports            => 8777,
269       collect_exported => false,
270     }
271     haproxy::balancermember { 'ceilometer':
272       listening_service => 'ceilometer',
273       ports             => '8777',
274       ipaddresses       => hiera('controller_host'),
275       options           => [],
276     }
277   }
278
279   if $swift_proxy_server {
280     haproxy::listen { 'swift_proxy_server':
281       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
282       ports            => 8080,
283       options          => { 'option' => [ 'httpchk GET /info' ] },
284       collect_exported => false,
285     }
286     haproxy::balancermember { 'swift_proxy_server':
287       listening_service => 'swift_proxy_server',
288       ports             => '8080',
289       ipaddresses       => hiera('controller_host'),
290       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
291     }
292   }
293
294   if $heat_api {
295     haproxy::listen { 'heat_api':
296       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
297       ports            => 8004,
298       options          => { 'option' => [ 'httpchk GET /' ] },
299       collect_exported => false,
300     }
301     haproxy::balancermember { 'heat_api':
302       listening_service => 'heat_api',
303       ports             => '8004',
304       ipaddresses       => hiera('controller_host'),
305       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
306     }
307   }
308
309   if $heat_cloudwatch {
310     haproxy::listen { 'heat_cloudwatch':
311       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
312       ports            => 8003,
313       options          => { 'option' => [ 'httpchk GET /' ] },
314       collect_exported => false,
315     }
316     haproxy::balancermember { 'heat_cloudwatch':
317       listening_service => 'heat_cloudwatch',
318       ports             => '8003',
319       ipaddresses       => hiera('controller_host'),
320       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
321     }
322   }
323
324   if $heat_cfn {
325     haproxy::listen { 'heat_cfn':
326       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
327       ports            => 8000,
328       options          => { 'option' => [ 'httpchk GET /' ] },
329       collect_exported => false,
330     }
331     haproxy::balancermember { 'heat_cfn':
332       listening_service => 'heat_cfn',
333       ports             => '8000',
334       ipaddresses       => hiera('controller_host'),
335       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
336     }
337   }
338
339   if $horizon {
340     haproxy::listen { 'horizon':
341       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
342       ports            => 80,
343       options          => { 'option' => [ 'httpchk GET /' ] },
344       collect_exported => false,
345     }
346     haproxy::balancermember { 'horizon':
347       listening_service => 'horizon',
348       ports             => '80',
349       ipaddresses       => hiera('controller_host'),
350       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
351     }
352   }
353
354   if $mysql {
355     haproxy::listen { 'mysql':
356       ipaddress        => [hiera('controller_virtual_ip')],
357       ports            => 3306,
358       options          => { 'timeout' => [ 'client 0', 'server 0' ] },
359       collect_exported => false,
360     }
361     haproxy::balancermember { 'mysql':
362       listening_service => 'mysql',
363       ports             => '3306',
364       ipaddresses       => hiera('controller_host'),
365       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
366     }
367   }
368
369   if $rabbitmq {
370     haproxy::listen { 'rabbitmq':
371       ipaddress        => [hiera('controller_virtual_ip'), hiera('public_virtual_ip')],
372       ports            => 5672,
373       options          => { 'timeout' => [ 'client 0', 'server 0' ] },
374       collect_exported => false,
375     }
376     haproxy::balancermember { 'rabbitmq':
377       listening_service => 'rabbitmq',
378       ports             => '5672',
379       ipaddresses       => hiera('controller_host'),
380       options           => ['check', 'inter 2000', 'rise 2', 'fall 5'],
381     }
382   }
383
384 }
385
386 include ::tripleo::loadbalancer