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