d78f2d07a0f68a7247b01640b71c26483428241f
[apex-tripleo-heat-templates.git] / puppet / manifests / overcloud_controller.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 $enable_pacemaker = str2bool(hiera('enable_pacemaker'))
28 $enable_keepalived = !$enable_pacemaker
29 if $::hostname == downcase(hiera('bootstrap_nodeid')) {
30   $pacemaker_master = true
31 } else {
32   $pacemaker_master = false
33 }
34
35 if hiera('step') >= 1 {
36
37   $controller_node_ips = split(hiera('controller_node_ips'), ',')
38
39   class { '::tripleo::loadbalancer' :
40     controller_hosts => $controller_node_ips,
41     manage_vip       => $enable_keepalived,
42   }
43
44   if $enable_pacemaker {
45     $pacemaker_cluster_members = regsubst(hiera('controller_node_ips'), ',', ' ', 'G')
46     user { 'hacluster':
47      ensure => present,
48     } ->
49     class { '::pacemaker':
50       hacluster_pwd => hiera('hacluster_pwd'),
51     } ->
52     class { '::pacemaker::corosync':
53       cluster_members => $pacemaker_cluster_members,
54       setup_cluster   => $pacemaker_master,
55     }
56     class { '::pacemaker::stonith':
57       disable => true,
58     }
59     if $pacemaker_master {
60       $control_vip = hiera('tripleo::loadbalancer::controller_virtual_ip')
61       pacemaker::resource::ip { 'control_vip':
62         ip_address => $control_vip,
63       }
64       $public_vip = hiera('tripleo::loadbalancer::public_virtual_ip')
65       pacemaker::resource::ip { 'public_vip':
66         ip_address => $public_vip,
67       }
68       pacemaker::resource::systemd { 'haproxy':
69         clone => true,
70       }
71     }
72   }
73
74 }
75
76 if hiera('step') >= 2 {
77
78   if count(hiera('ntp::servers')) > 0 {
79     include ::ntp
80   }
81
82   # MongoDB
83   if downcase(hiera('ceilometer_backend')) == 'mongodb' {
84     include ::mongodb::globals
85     include ::mongodb::server
86     $mongo_node_ips = split(hiera('mongo_node_ips'), ',')
87     $mongo_node_ips_with_port = suffix($mongo_node_ips, ':27017')
88     $mongo_node_string = join($mongo_node_ips_with_port, ',')
89
90     $mongodb_replset = hiera('mongodb::server::replset')
91     $ceilometer_mongodb_conn_string = "mongodb://${mongo_node_string}/ceilometer?replicaSet=${mongodb_replset}"
92     if downcase(hiera('bootstrap_nodeid')) == $::hostname {
93       mongodb_replset { $mongodb_replset :
94         members => $mongo_node_ips_with_port,
95       }
96     }
97   }
98
99   # Redis
100   $redis_node_ips = split(hiera('redis_node_ips'), ',')
101   $redis_master_hostname = downcase(hiera('bootstrap_nodeid'))
102
103   if $redis_master_hostname == $::hostname {
104     $slaveof = undef
105   } else {
106     $slaveof = "${redis_master_hostname} 6379"
107   }
108   class {'::redis' :
109     slaveof => $slaveof,
110   }
111
112   if count($redis_node_ips) > 1 {
113     Class['::tripleo::redis_notification'] -> Service['redis-sentinel']
114     include ::redis::sentinel
115     class {'::tripleo::redis_notification' :
116       haproxy_monitor_ip => hiera('tripleo::loadbalancer::controller_virtual_ip'),
117     }
118   }
119
120   if str2bool(hiera('enable_galera', 'true')) {
121     $mysql_config_file = '/etc/my.cnf.d/galera.cnf'
122   } else {
123     $mysql_config_file = '/etc/my.cnf.d/server.cnf'
124   }
125   # TODO Galara
126   class { 'mysql::server':
127     config_file => $mysql_config_file,
128     override_options => {
129       'mysqld' => {
130         'bind-address' => hiera('controller_host')
131       }
132     }
133   }
134
135   # FIXME: this should only occur on the bootstrap host (ditto for db syncs)
136   # Create all the database schemas
137   # Example DSN format: mysql://user:password@host/dbname
138   $allowed_hosts = ['%',hiera('controller_host')]
139   $keystone_dsn = split(hiera('keystone::database_connection'), '[@:/?]')
140   class { 'keystone::db::mysql':
141     user          => $keystone_dsn[3],
142     password      => $keystone_dsn[4],
143     host          => $keystone_dsn[5],
144     dbname        => $keystone_dsn[6],
145     allowed_hosts => $allowed_hosts,
146   }
147   $glance_dsn = split(hiera('glance::api::database_connection'), '[@:/?]')
148   class { 'glance::db::mysql':
149     user          => $glance_dsn[3],
150     password      => $glance_dsn[4],
151     host          => $glance_dsn[5],
152     dbname        => $glance_dsn[6],
153     allowed_hosts => $allowed_hosts,
154   }
155   $nova_dsn = split(hiera('nova::database_connection'), '[@:/?]')
156   class { 'nova::db::mysql':
157     user          => $nova_dsn[3],
158     password      => $nova_dsn[4],
159     host          => $nova_dsn[5],
160     dbname        => $nova_dsn[6],
161     allowed_hosts => $allowed_hosts,
162   }
163   $neutron_dsn = split(hiera('neutron::server::database_connection'), '[@:/?]')
164   class { 'neutron::db::mysql':
165     user          => $neutron_dsn[3],
166     password      => $neutron_dsn[4],
167     host          => $neutron_dsn[5],
168     dbname        => $neutron_dsn[6],
169     allowed_hosts => $allowed_hosts,
170   }
171   $cinder_dsn = split(hiera('cinder::database_connection'), '[@:/?]')
172   class { 'cinder::db::mysql':
173     user          => $cinder_dsn[3],
174     password      => $cinder_dsn[4],
175     host          => $cinder_dsn[5],
176     dbname        => $cinder_dsn[6],
177     allowed_hosts => $allowed_hosts,
178   }
179   $heat_dsn = split(hiera('heat::database_connection'), '[@:/?]')
180   class { 'heat::db::mysql':
181     user          => $heat_dsn[3],
182     password      => $heat_dsn[4],
183     host          => $heat_dsn[5],
184     dbname        => $heat_dsn[6],
185     allowed_hosts => $allowed_hosts,
186   }
187   if downcase(hiera('ceilometer_backend')) == 'mysql' {
188     $ceilometer_dsn = split(hiera('ceilometer_mysql_conn_string'), '[@:/?]')
189     class { 'ceilometer::db::mysql':
190       user          => $ceilometer_dsn[3],
191       password      => $ceilometer_dsn[4],
192       host          => $ceilometer_dsn[5],
193       dbname        => $ceilometer_dsn[6],
194       allowed_hosts => $allowed_hosts,
195     }
196   }
197
198   if $enable_pacemaker {
199     # the module ignores erlang_cookie if cluster_config is false
200     file { '/var/lib/rabbitmq/.erlang.cookie':
201       ensure  => 'present',
202       owner   => 'rabbitmq',
203       group   => 'rabbitmq',
204       mode    => '0400',
205       content => hiera('rabbitmq::erlang_cookie'),
206       replace => true,
207     } ->
208     class { '::rabbitmq':
209       service_manage        => false,
210       environment_variables => {
211         'RABBITMQ_NODENAME' => "rabbit@$::hostname",
212       },
213     }
214     if $pacemaker_master {
215       pacemaker::resource::ocf { 'rabbitmq':
216         resource_name => 'heartbeat:rabbitmq-cluster',
217         options       => 'set_policy=\'ha-all ^(?!amq\.).* {"ha-mode":"all"}\'',
218         clone         => true,
219         require       => Class['::rabbitmq'],
220       }
221     }
222   } else {
223     $rabbit_nodes = split(hiera('rabbit_node_ips'), ',')
224     if count($rabbit_nodes) > 1 {
225       class { '::rabbitmq':
226         config_cluster  => true,
227         cluster_nodes   => $rabbit_nodes,
228       }
229       rabbitmq_policy { 'ha-all@/':
230         pattern    => '^(?!amq\.).*',
231         definition => {
232           'ha-mode' => 'all',
233         },
234       }
235     } else {
236       include ::rabbitmq
237     }
238   }
239
240   # pre-install swift here so we can build rings
241   include ::swift
242
243   $cinder_enable_rbd_backend = hiera('cinder_enable_rbd_backend', false)
244   $enable_ceph = $cinder_enable_rbd_backend
245
246   if $enable_ceph {
247     class { 'ceph::profile::params':
248       mon_initial_members => downcase(hiera('ceph_mon_initial_members'))
249     }
250     include ::ceph::profile::mon
251   }
252
253   if str2bool(hiera('enable_ceph_storage', 'false')) {
254     include ::ceph::profile::client
255     include ::ceph::profile::osd
256   }
257
258 } #END STEP 2
259
260 if hiera('step') >= 3 {
261
262   include ::keystone
263
264   #TODO: need a cleanup-keystone-tokens.sh solution here
265   keystone_config {
266     'ec2/driver': value => 'keystone.contrib.ec2.backends.sql.Ec2';
267   }
268   file { [ '/etc/keystone/ssl', '/etc/keystone/ssl/certs', '/etc/keystone/ssl/private' ]:
269     ensure  => 'directory',
270     owner   => 'keystone',
271     group   => 'keystone',
272     require => Package['keystone'],
273   }
274   file { '/etc/keystone/ssl/certs/signing_cert.pem':
275     content => hiera('keystone_signing_certificate'),
276     owner   => 'keystone',
277     group   => 'keystone',
278     notify  => Service['keystone'],
279     require => File['/etc/keystone/ssl/certs'],
280   }
281   file { '/etc/keystone/ssl/private/signing_key.pem':
282     content => hiera('keystone_signing_key'),
283     owner   => 'keystone',
284     group   => 'keystone',
285     notify  => Service['keystone'],
286     require => File['/etc/keystone/ssl/private'],
287   }
288   file { '/etc/keystone/ssl/certs/ca.pem':
289     content => hiera('keystone_ca_certificate'),
290     owner   => 'keystone',
291     group   => 'keystone',
292     notify  => Service['keystone'],
293     require => File['/etc/keystone/ssl/certs'],
294   }
295
296   $glance_backend = downcase(hiera('glance_backend', 'swift'))
297   case $glance_backend {
298       swift: { $glance_store = 'glance.store.swift.Store' }
299       file: { $glance_store = 'glance.store.filesystem.Store' }
300       rbd: { $glance_store = 'glance.store.rbd.Store' }
301       default: { fail('Unrecognized glance_backend parameter.') }
302   }
303
304   # TODO: notifications, scrubber, etc.
305   include ::glance
306   class { 'glance::api':
307     known_stores => [$glance_store]
308   }
309   include ::glance::registry
310   include join(['::glance::backend::', $glance_backend])
311
312   class { 'nova':
313     glance_api_servers     => join([hiera('glance_protocol'), '://', hiera('controller_virtual_ip'), ':', hiera('glance_port')]),
314   }
315
316   include ::nova::api
317   include ::nova::cert
318   include ::nova::conductor
319   include ::nova::consoleauth
320   include ::nova::network::neutron
321   include ::nova::vncproxy
322   include ::nova::scheduler
323
324   include ::neutron
325   include ::neutron::server
326   include ::neutron::agents::dhcp
327   include ::neutron::agents::l3
328
329   file { '/etc/neutron/dnsmasq-neutron.conf':
330     content => hiera('neutron_dnsmasq_options'),
331     owner   => 'neutron',
332     group   => 'neutron',
333     notify  => Service['neutron-dhcp-service'],
334     require => Package['neutron'],
335   }
336
337   class { 'neutron::plugins::ml2':
338     flat_networks        => split(hiera('neutron_flat_networks'), ','),
339     tenant_network_types => [hiera('neutron_tenant_network_type')],
340     type_drivers         => [hiera('neutron_tenant_network_type')],
341   }
342
343   class { 'neutron::agents::ml2::ovs':
344     bridge_mappings  => split(hiera('neutron_bridge_mappings'), ','),
345     tunnel_types     => split(hiera('neutron_tunnel_types'), ','),
346   }
347
348   class { 'neutron::agents::metadata':
349     auth_url => join(['http://', hiera('controller_virtual_ip'), ':35357/v2.0']),
350   }
351
352   Service['neutron-server'] -> Service['neutron-dhcp-service']
353   Service['neutron-server'] -> Service['neutron-l3']
354   Service['neutron-server'] -> Service['neutron-ovs-agent-service']
355   Service['neutron-server'] -> Service['neutron-metadata']
356
357   include ::cinder
358   include ::cinder::api
359   include ::cinder::glance
360   include ::cinder::scheduler
361   include ::cinder::volume
362   class {'cinder::setup_test_volume':
363     size => join([hiera('cinder_lvm_loop_device_size'), 'M']),
364   }
365
366   $cinder_enable_iscsi = hiera('cinder_enable_iscsi_backend', true)
367   if $cinder_enable_iscsi {
368     $cinder_iscsi_backend = 'tripleo_iscsi'
369
370     cinder::backend::iscsi { $cinder_iscsi_backend :
371       iscsi_ip_address => hiera('cinder_iscsi_ip_address'),
372       iscsi_helper     => hiera('cinder_iscsi_helper'),
373     }
374   }
375
376   if $enable_ceph {
377
378     Ceph_pool {
379       pg_num  => hiera('ceph::profile::params::osd_pool_default_pg_num'),
380       pgp_num => hiera('ceph::profile::params::osd_pool_default_pgp_num'),
381       size    => hiera('ceph::profile::params::osd_pool_default_size'),
382     }
383
384     $ceph_pools = hiera('ceph_pools')
385     ceph::pool { $ceph_pools : }
386   }
387
388   if $cinder_enable_rbd_backend {
389     $cinder_rbd_backend = 'tripleo_ceph'
390
391     cinder_config {
392       "${cinder_rbd_backend}/host": value => 'hostgroup';
393     }
394
395     cinder::backend::rbd { $cinder_rbd_backend :
396       rbd_pool        => 'volumes',
397       rbd_user        => 'openstack',
398       rbd_secret_uuid => hiera('ceph::profile::params::fsid'),
399       require         => Ceph::Pool['volumes'],
400     }
401   }
402
403   $cinder_enabled_backends = delete_undef_values([$cinder_iscsi_backend, $cinder_rbd_backend])
404   class { '::cinder::backends' :
405     enabled_backends => $cinder_enabled_backends,
406   }
407
408   # swift proxy
409   include ::memcached
410   include ::swift::proxy
411   include ::swift::proxy::proxy_logging
412   include ::swift::proxy::healthcheck
413   include ::swift::proxy::cache
414   include ::swift::proxy::keystone
415   include ::swift::proxy::authtoken
416   include ::swift::proxy::staticweb
417   include ::swift::proxy::ceilometer
418   include ::swift::proxy::ratelimit
419   include ::swift::proxy::catch_errors
420   include ::swift::proxy::tempurl
421   include ::swift::proxy::formpost
422
423   # swift storage
424   if str2bool(hiera('enable_swift_storage', 'true')) {
425     class {'swift::storage::all':
426       mount_check => str2bool(hiera('swift_mount_check'))
427     }
428     if(!defined(File['/srv/node'])) {
429       file { '/srv/node':
430         ensure  => directory,
431         owner   => 'swift',
432         group   => 'swift',
433         require => Package['openstack-swift'],
434       }
435     }
436     $swift_components = ['account', 'container', 'object']
437     swift::storage::filter::recon { $swift_components : }
438     swift::storage::filter::healthcheck { $swift_components : }
439   }
440
441   # Ceilometer
442   $ceilometer_backend = downcase(hiera('ceilometer_backend'))
443   case $ceilometer_backend {
444     /mysql/ : {
445       $ceilometer_database_connection = hiera('ceilometer_mysql_conn_string')
446     }
447     default : {
448       $ceilometer_database_connection = $ceilometer_mongodb_conn_string
449     }
450   }
451   include ::ceilometer
452   include ::ceilometer::api
453   include ::ceilometer::agent::notification
454   include ::ceilometer::agent::central
455   include ::ceilometer::alarm::notifier
456   include ::ceilometer::alarm::evaluator
457   include ::ceilometer::expirer
458   include ::ceilometer::collector
459   class { '::ceilometer::db' :
460     database_connection => $ceilometer_database_connection,
461   }
462   class { 'ceilometer::agent::auth':
463     auth_url => join(['http://', hiera('controller_virtual_ip'), ':5000/v2.0']),
464   }
465
466   Cron <| title == 'ceilometer-expirer' |> { command => "sleep $((\$(od -A n -t d -N 3 /dev/urandom) % 86400)) && ${::ceilometer::params::expirer_command}" }
467
468   # Heat
469   include ::heat
470   include ::heat::api
471   include ::heat::api_cfn
472   include ::heat::api_cloudwatch
473   include ::heat::engine
474
475   $snmpd_user = hiera('snmpd_readonly_user_name')
476   snmp::snmpv3_user { $snmpd_user:
477     authtype => 'MD5',
478     authpass => hiera('snmpd_readonly_user_password'),
479   }
480   class { 'snmp':
481     agentaddress => ['udp:161','udp6:[::1]:161'],
482     snmpd_config => [ join(['rouser ', hiera('snmpd_readonly_user_name')]), 'proc  cron', 'includeAllDisks  10%', 'master agentx', 'trapsink localhost public', 'iquerySecName internalUser', 'rouser internalUser', 'defaultMonitors yes', 'linkUpDownNotifications yes' ],
483   }
484
485 } #END STEP 3