replicate_pri_addnodes.rb 1.35 KB
#
# Author:: Earth U (<sysadmin @ chromedia.com>)
# Cookbook Name:: cfe-mongodb
# Recipe:: replicate_pri_addnodes
#
# Copyright (C) 2016, Chromedia Far East, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

mongod = node['mongodb3']['config']['mongod']
ip     = (mongod['net']['bindIp'].split(','))[-1]
port   = mongod['net']['port']

com = "sleep #{node[cookbook_name]['rs']['delay']} "\
      "&& mongo --host #{ip} --port #{port} "\
      "-u root -p #{node[cookbook_name]['db']['pass_root']} "\
      "--authenticationDatabase admin --eval 'rs.add<<1>>(\"<<2>>\")' "\
      ">> #{::File.dirname(mongod['systemLog']['path'])}/primary_addnodes"

node[cookbook_name]['rs']['nodes']['secondary'].each do |sec|
  execute com.sub('<<1>>', '').sub('<<2>>', sec)
end

node[cookbook_name]['rs']['nodes']['arbiter'].each do |arb|
  execute com.sub('<<1>>', 'Arb').sub('<<2>>', arb)
end