Surround MongoDB IPs with braces in the connection string if IPv6

Change-Id: I9ed917f32b3de95beb234ade4819a8b96affe3e9
This commit is contained in:
Giulio Fidente 2016-01-20 13:01:21 +01:00 committed by Attila Darazs
parent 31ffe53d75
commit e781f5fa98
2 changed files with 26 additions and 5 deletions

View File

@ -48,14 +48,24 @@ if hiera('step') >= 2 {
include ::mongodb::globals
include ::mongodb::server
$mongo_node_ips_with_port = suffix(hiera('mongo_node_ips'), ':27017')
# NOTE(gfidente): We need to pass the list of IPv6 addresses *with* port and
# without the brackets as 'members' argument for the 'mongodb_replset'
# resource.
if str2bool(hiera('mongodb::server::ipv6', false)) {
$mongo_node_ips_with_port_prefixed = prefix(hiera('mongo_node_ips'), '[')
$mongo_node_ips_with_port = suffix($mongo_node_ips_with_port_prefixed, ']:27017')
$mongo_node_ips_with_port_nobr = suffix(hiera('mongo_node_ips'), ':27017')
} else {
$mongo_node_ips_with_port = suffix(hiera('mongo_node_ips'), ':27017')
$mongo_node_ips_with_port_nobr = suffix(hiera('mongo_node_ips'), ':27017')
}
$mongo_node_string = join($mongo_node_ips_with_port, ',')
$mongodb_replset = hiera('mongodb::server::replset')
$ceilometer_mongodb_conn_string = "mongodb://${mongo_node_string}/ceilometer?replicaSet=${mongodb_replset}"
if downcase(hiera('bootstrap_nodeid')) == $::hostname {
mongodb_replset { $mongodb_replset :
members => $mongo_node_ips_with_port,
members => $mongo_node_ips_with_port_nobr,
}
}
}

View File

@ -201,8 +201,19 @@ if hiera('step') >= 1 {
if hiera('step') >= 2 {
# NOTE(gfidente): the following vars are needed on all nodes so they
# need to stay out of pacemaker_master conditional
$mongo_node_ips_with_port = suffix(hiera('mongo_node_ips'), ':27017')
# need to stay out of pacemaker_master conditional.
# The addresses mangling will hopefully go away when we'll be able to
# configure the connection string via hostnames, until then, we need to pass
# the list of IPv6 addresses *with* port and without the brackets as 'members'
# argument for the 'mongodb_replset' resource.
if str2bool(hiera('mongodb::server::ipv6', false)) {
$mongo_node_ips_with_port_prefixed = prefix(hiera('mongo_node_ips'), '[')
$mongo_node_ips_with_port = suffix($mongo_node_ips_with_port_prefixed, ']:27017')
$mongo_node_ips_with_port_nobr = suffix(hiera('mongo_node_ips'), ':27017')
} else {
$mongo_node_ips_with_port = suffix(hiera('mongo_node_ips'), ':27017')
$mongo_node_ips_with_port_nobr = suffix(hiera('mongo_node_ips'), ':27017')
}
$mongodb_replset = hiera('mongodb::server::replset')
if $pacemaker_master {
@ -431,7 +442,7 @@ if hiera('step') >= 2 {
before => Mongodb_replset[$mongodb_replset],
}
mongodb_replset { $mongodb_replset :
members => $mongo_node_ips_with_port,
members => $mongo_node_ips_with_port_nobr,
}
}