Composable roles within services - MongoDB
[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 include ::tripleo::packages
17 include ::tripleo::firewall
18
19 $enable_load_balancer = hiera('enable_load_balancer', true)
20
21 if hiera('step') >= 1 {
22
23   create_resources(kmod::load, hiera('kernel_modules'), {})
24   create_resources(sysctl::value, hiera('sysctl_settings'), {})
25   Exec <| tag == 'kmod::load' |>  -> Sysctl <| |>
26
27 }
28
29 if hiera('step') >= 2 {
30
31   if count(hiera('ntp::servers')) > 0 {
32     include ::ntp
33   }
34
35   include ::timezone
36
37   # MongoDB
38   if downcase(hiera('ceilometer_backend')) == 'mongodb' {
39     # NOTE(gfidente): We need to pass the list of IPv6 addresses *with* port and
40     # without the brackets as 'members' argument for the 'mongodb_replset'
41     # resource.
42     if str2bool(hiera('mongodb::server::ipv6', false)) {
43       $mongo_node_ips_with_port_prefixed = prefix(hiera('mongo_node_ips'), '[')
44       $mongo_node_ips_with_port = suffix($mongo_node_ips_with_port_prefixed, ']:27017')
45       $mongo_node_ips_with_port_nobr = suffix(hiera('mongo_node_ips'), ':27017')
46     } else {
47       $mongo_node_ips_with_port = suffix(hiera('mongo_node_ips'), ':27017')
48       $mongo_node_ips_with_port_nobr = suffix(hiera('mongo_node_ips'), ':27017')
49     }
50     $mongo_node_string = join($mongo_node_ips_with_port, ',')
51
52     $mongodb_replset = hiera('mongodb::server::replset')
53     $ceilometer_mongodb_conn_string = "mongodb://${mongo_node_string}/ceilometer?replicaSet=${mongodb_replset}"
54   }
55
56   if str2bool(hiera('enable_galera', true)) {
57     $mysql_config_file = '/etc/my.cnf.d/galera.cnf'
58   } else {
59     $mysql_config_file = '/etc/my.cnf.d/server.cnf'
60   }
61   # TODO Galara
62   # FIXME: due to https://bugzilla.redhat.com/show_bug.cgi?id=1298671 we
63   # set bind-address to a hostname instead of an ip address; to move Mysql
64   # from internal_api on another network we'll have to customize both
65   # MysqlNetwork and ControllerHostnameResolveNetwork in ServiceNetMap
66   class { '::mysql::server':
67     config_file             => $mysql_config_file,
68     override_options        => {
69       'mysqld' => {
70         'bind-address'     => $::hostname,
71         'max_connections'  => hiera('mysql_max_connections'),
72         'open_files_limit' => '-1',
73       },
74     },
75     remove_default_accounts => true,
76   }
77
78   # FIXME: this should only occur on the bootstrap host (ditto for db syncs)
79   # Create all the database schemas
80   include ::nova::db::mysql
81   include ::nova::db::mysql_api
82   if downcase(hiera('gnocchi_indexer_backend')) == 'mysql' {
83     include ::gnocchi::db::mysql
84   }
85   if downcase(hiera('ceilometer_backend')) == 'mysql' {
86     include ::ceilometer::db::mysql
87     include ::aodh::db::mysql
88   }
89
90   $enable_ceph = hiera('ceph_storage_count', 0) > 0 or hiera('enable_ceph_storage', false)
91
92   if $enable_ceph {
93     $mon_initial_members = downcase(hiera('ceph_mon_initial_members'))
94     if str2bool(hiera('ceph_ipv6', false)) {
95       $mon_host = hiera('ceph_mon_host_v6')
96     } else {
97       $mon_host = hiera('ceph_mon_host')
98     }
99     class { '::ceph::profile::params':
100       mon_initial_members => $mon_initial_members,
101       mon_host            => $mon_host,
102     }
103     include ::ceph::conf
104     include ::ceph::profile::mon
105   }
106
107   if str2bool(hiera('enable_ceph_storage', false)) {
108     if str2bool(hiera('ceph_osd_selinux_permissive', true)) {
109       exec { 'set selinux to permissive on boot':
110         command => "sed -ie 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config",
111         onlyif  => "test -f /etc/selinux/config && ! grep '^SELINUX=permissive' /etc/selinux/config",
112         path    => ['/usr/bin', '/usr/sbin'],
113       }
114
115       exec { 'set selinux to permissive':
116         command => 'setenforce 0',
117         onlyif  => "which setenforce && getenforce | grep -i 'enforcing'",
118         path    => ['/usr/bin', '/usr/sbin'],
119       } -> Class['ceph::profile::osd']
120     }
121
122     include ::ceph::conf
123     include ::ceph::profile::osd
124   }
125
126   if str2bool(hiera('enable_external_ceph', false)) {
127     if str2bool(hiera('ceph_ipv6', false)) {
128       $mon_host = hiera('ceph_mon_host_v6')
129     } else {
130       $mon_host = hiera('ceph_mon_host')
131     }
132     class { '::ceph::profile::params':
133       mon_host            => $mon_host,
134     }
135     include ::ceph::conf
136     include ::ceph::profile::client
137   }
138
139 } #END STEP 2
140
141 if hiera('step') >= 4 {
142
143   $nova_ipv6 = hiera('nova::use_ipv6', false)
144   if $nova_ipv6 {
145     $memcached_servers = suffix(hiera('memcache_node_ips_v6'), ':11211')
146   } else {
147     $memcached_servers = suffix(hiera('memcache_node_ips'), ':11211')
148   }
149
150   class { '::nova' :
151     memcached_servers => $memcached_servers
152   }
153   include ::nova::config
154   include ::nova::api
155   include ::nova::consoleauth
156   include ::nova::network::neutron
157   include ::nova::vncproxy
158   include ::nova::scheduler
159   include ::nova::scheduler::filter
160
161   if hiera('neutron::core_plugin') == 'midonet.neutron.plugin_v1.MidonetPluginV2' {
162
163     # TODO(devvesa) provide non-controller ips for these services
164     $zookeeper_node_ips = hiera('neutron_api_node_ips')
165     $cassandra_node_ips = hiera('neutron_api_node_ips')
166
167     # Run zookeeper in the controller if configured
168     if hiera('enable_zookeeper_on_controller') {
169       class {'::tripleo::cluster::zookeeper':
170         zookeeper_server_ips => $zookeeper_node_ips,
171         # TODO: create a 'bind' hiera key for zookeeper
172         zookeeper_client_ip  => hiera('neutron::bind_host'),
173         zookeeper_hostnames  => hiera('controller_node_names')
174       }
175     }
176
177     # Run cassandra in the controller if configured
178     if hiera('enable_cassandra_on_controller') {
179       class {'::tripleo::cluster::cassandra':
180         cassandra_servers => $cassandra_node_ips,
181         # TODO: create a 'bind' hiera key for cassandra
182         cassandra_ip      => hiera('neutron::bind_host'),
183       }
184     }
185
186     class {'::tripleo::network::midonet::agent':
187       zookeeper_servers => $zookeeper_node_ips,
188       cassandra_seeds   => $cassandra_node_ips
189     }
190
191     class {'::tripleo::network::midonet::api':
192       zookeeper_servers    => $zookeeper_node_ips,
193       vip                  => hiera('public_virtual_ip'),
194       keystone_ip          => hiera('public_virtual_ip'),
195       keystone_admin_token => hiera('keystone::admin_token'),
196       # TODO: create a 'bind' hiera key for api
197       bind_address         => hiera('neutron::bind_host'),
198       admin_password       => hiera('admin_password')
199     }
200
201     # TODO: find a way to get an empty list from hiera
202     class {'::neutron':
203       service_plugins => []
204     }
205
206   }
207   else {
208
209     # ML2 plugin
210     include ::neutron
211   }
212
213   include ::neutron::config
214
215   # If the value of core plugin is set to 'nuage' or'opencontrail' or 'plumgrid',
216   # include nuage or opencontrail or plumgrid core plugins
217   # else use the default value of 'ml2'
218   if hiera('neutron::core_plugin') == 'neutron.plugins.nuage.plugin.NuagePlugin' {
219     include ::neutron::plugins::nuage
220   } elsif hiera('neutron::core_plugin') == 'neutron_plugin_contrail.plugins.opencontrail.contrail_plugin.NeutronPluginContrailCoreV2' {
221     include ::neutron::plugins::opencontrail
222   }
223   elsif hiera('neutron::core_plugin') == 'networking_plumgrid.neutron.plugins.plugin.NeutronPluginPLUMgridV2' {
224     class { '::neutron::plugins::plumgrid' :
225       connection                   => hiera('neutron::server::database_connection'),
226       controller_priv_host         => hiera('keystone_admin_api_vip'),
227       admin_password               => hiera('admin_password'),
228       metadata_proxy_shared_secret => hiera('nova::api::neutron_metadata_proxy_shared_secret'),
229     }
230   } else {
231
232     # If the value of core plugin is set to 'midonet',
233     # skip all the ML2 configuration
234     if hiera('neutron::core_plugin') == 'midonet.neutron.plugin_v1.MidonetPluginV2' {
235
236       class {'::neutron::plugins::midonet':
237         midonet_api_ip    => hiera('public_virtual_ip'),
238         keystone_tenant   => hiera('neutron::server::auth_tenant'),
239         keystone_password => hiera('neutron::server::password')
240       }
241     }
242
243     Service['neutron-server'] -> Service['neutron-metadata']
244
245   }
246
247   if $enable_ceph {
248     $ceph_pools = hiera('ceph_pools')
249     ceph::pool { $ceph_pools :
250       pg_num  => hiera('ceph::profile::params::osd_pool_default_pg_num'),
251       pgp_num => hiera('ceph::profile::params::osd_pool_default_pgp_num'),
252       size    => hiera('ceph::profile::params::osd_pool_default_size'),
253     }
254   }
255
256   # swift storage
257   if str2bool(hiera('enable_swift_storage', true)) {
258     class { '::swift::storage::all':
259       mount_check => str2bool(hiera('swift_mount_check')),
260     }
261     if(!defined(File['/srv/node'])) {
262       file { '/srv/node':
263         ensure  => directory,
264         owner   => 'swift',
265         group   => 'swift',
266         require => Package['openstack-swift'],
267       }
268     }
269     $swift_components = ['account', 'container', 'object']
270     swift::storage::filter::recon { $swift_components : }
271     swift::storage::filter::healthcheck { $swift_components : }
272   }
273
274   # Ceilometer
275   $ceilometer_backend = downcase(hiera('ceilometer_backend'))
276   case $ceilometer_backend {
277     /mysql/ : {
278       $ceilometer_database_connection = hiera('ceilometer_mysql_conn_string')
279     }
280     default : {
281       $ceilometer_database_connection = $ceilometer_mongodb_conn_string
282     }
283   }
284   include ::ceilometer
285   include ::ceilometer::config
286   include ::ceilometer::api
287   include ::ceilometer::agent::notification
288   include ::ceilometer::agent::central
289   include ::ceilometer::expirer
290   include ::ceilometer::collector
291   include ::ceilometer::agent::auth
292   include ::ceilometer::dispatcher::gnocchi
293   class { '::ceilometer::db' :
294     database_connection => $ceilometer_database_connection,
295   }
296
297   Cron <| title == 'ceilometer-expirer' |> { command => "sleep $((\$(od -A n -t d -N 3 /dev/urandom) % 86400)) && ${::ceilometer::params::expirer_command}" }
298
299   # Aodh
300   class { '::aodh' :
301     database_connection => $ceilometer_database_connection,
302   }
303   include ::aodh::db::sync
304   # To manage the upgrade:
305   Exec['ceilometer-dbsync'] -> Exec['aodh-db-sync']
306   include ::aodh::auth
307   include ::aodh::api
308   include ::aodh::wsgi::apache
309   include ::aodh::evaluator
310   include ::aodh::notifier
311   include ::aodh::listener
312   include ::aodh::client
313
314   # Horizon
315   include ::apache::mod::remoteip
316   if 'cisco_n1kv' in hiera('neutron::plugins::ml2::mechanism_drivers') {
317     $_profile_support = 'cisco'
318   } else {
319     $_profile_support = 'None'
320   }
321   $neutron_options   = {'profile_support' => $_profile_support }
322
323   $memcached_ipv6 = hiera('memcached_ipv6', false)
324   if $memcached_ipv6 {
325     $horizon_memcached_servers = hiera('memcache_node_ips_v6', '[::1]')
326   } else {
327     $horizon_memcached_servers = hiera('memcache_node_ips', '127.0.0.1')
328   }
329
330   class { '::horizon':
331     cache_server_ip => $horizon_memcached_servers,
332     neutron_options => $neutron_options,
333   }
334
335   # Gnocchi
336   $gnocchi_database_connection = hiera('gnocchi_mysql_conn_string')
337   class { '::gnocchi':
338     database_connection => $gnocchi_database_connection,
339   }
340   include ::gnocchi::api
341   include ::gnocchi::wsgi::apache
342   include ::gnocchi::client
343   include ::gnocchi::db::sync
344   include ::gnocchi::storage
345   include ::gnocchi::metricd
346   include ::gnocchi::statsd
347   $gnocchi_backend = downcase(hiera('gnocchi_backend', 'swift'))
348   case $gnocchi_backend {
349       'swift': { include ::gnocchi::storage::swift }
350       'file': { include ::gnocchi::storage::file }
351       'rbd': { include ::gnocchi::storage::ceph }
352       default: { fail('Unrecognized gnocchi_backend parameter.') }
353   }
354
355   $snmpd_user = hiera('snmpd_readonly_user_name')
356   snmp::snmpv3_user { $snmpd_user:
357     authtype => 'MD5',
358     authpass => hiera('snmpd_readonly_user_password'),
359   }
360   class { '::snmp':
361     agentaddress => ['udp:161','udp6:[::1]:161'],
362     snmpd_config => [ join(['createUser ', hiera('snmpd_readonly_user_name'), ' MD5 "', hiera('snmpd_readonly_user_password'), '"']), join(['rouser ', hiera('snmpd_readonly_user_name')]), 'proc  cron', 'includeAllDisks  10%', 'master agentx', 'trapsink localhost public', 'iquerySecName internalUser', 'rouser internalUser', 'defaultMonitors yes', 'linkUpDownNotifications yes' ],
363   }
364
365   hiera_include('controller_classes')
366
367 } #END STEP 4
368
369 if hiera('step') >= 5 {
370   $nova_enable_db_purge = hiera('nova_enable_db_purge', true)
371
372   if $nova_enable_db_purge {
373     include ::nova::cron::archive_deleted_rows
374   }
375 } #END STEP 5
376
377 $package_manifest_name = join(['/var/lib/tripleo/installed-packages/overcloud_controller', hiera('step')])
378 package_manifest{$package_manifest_name: ensure => present}