Closed wdeviers closed 6 years ago
When using the replicaset, the way we do things is using the chef
search to identify and configure the replicaset nodes.
So by definition we can't create a mongodb instance AND configure the replicaset on the same chef run, because the node needs at least a successful chef run to listed on chef server.
The current process in order to create the replicaset is documented here.
But simplifying is:
sc-mongodb::replicaset
with the node['mongodb']['auto_configure']['replicaset'] = false
in all your replicated machines.sc-mongodb::replicaset
with the node['mongodb']['auto_configure']['replicaset'] = true
in a single node in the cluster.Does this makes sense to you? If it does I'll close the issue :)
It makes sense, but I'm not sure it's addressing this issue. mongod wouldn't start regardless of the replicaset flag. Let me do some more experimentation though. Thanks!
You're trying to run only the sc-mongodb::replicaset
cookbook?
Can you tell more about your environment so I can understand better?
On a side note, I have a cluster of mongodb myself and use the setup I described earlier, and don't have any issues with that.
The wording in the documentation seems a little odd to me. In a scenario with 3 nodes, are we supposed to first install the sc-mongodb::replicaset
recipe to the first two nodes with node['mongodb']['auto_configure']['replicaset'] = false
. Then after chef has ran on both of those, run sc-mongodb::replicaset
on the 3rd node with node['mongodb']['auto_configure']['replicaset'] = true
?
I've been attempting this and I have not had any luck getting it to work so far. I'll update here if I make any progress.
Error message when following the steps above for reference:
NoMethodError
-------------
undefined method `[]' for nil:NilClass
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/sc-mongodb/libraries/mongodb.rb:74:in `configure_replicaset'
/var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:246:in `block (3 levels) in from_file'
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb
244: ruby_block 'config_replicaset' do
245: block do
246: MongoDB.configure_replicaset(node, replicaset_name, rs_nodes) unless new_resource.replicaset.nil?
247: end
248: action :nothing
249: end
250:
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:244:in `block in from_file'
ruby_block("config_replicaset") do
params {:mongodb_type=>"mongod", :action=>[:enable, :start], :logpath=>"/var/log/mongodb/mongod.log", :configservers=>[], :replicaset=>true, :notifies=>[], :not_if=>[], :name=>"mongod"}
action [:nothing]
retries 0
retry_delay 2
default_guard_interpreter :default
block_name "config_replicaset"
declared_type :ruby_block
cookbook_name "sc-mongodb"
recipe_name "replicaset"
block #<Proc:0x0000000003be0ef8@/var/chef/cache/cookbooks/sc-mongodb/definitions/mongodb.rb:245>
end
System Info:
------------
chef_version=12.22.5
platform=ubuntu
platform_version=16.04
ruby=ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
program_name=chef-client worker: ppid=12395;start=19:53:50;
executable=/opt/chef/bin/chef-client
Nevermind, this was fixed in the release of 1.2.0.
Seems not an issue anymore, closing.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
On 1.0.0, Chef 12.21.31. Attempting to configure replica sets. The code beginning on line 34 of libraries/mongodb.rb:
begin connection = nil rescue_connection_failure do connection = Mongo::Connection.new('localhost', node['mongodb']['config']['port'], op_timeout: 20, slave_ok: true) connection.database_names # check connection end rescue => e Chef::Log.warn("Could not connect to database: 'localhost:#{node['mongodb']['config']['port']}', reason: #{e}") return end
When this executes (as called from definitions/mongodb.rb ~ :284), mongod is not running. I've hit my time-box limit for trying to use this cookbook, but as near as I can tell, the interpolation for the service definition in the same file doesn't work as expected.
Using
action: [:enable, :start],
in the definition for :mongodb_instance appears not to work. When I remove the variable and replace it with just :start, the service starts as expected, which lets that code block return clean, which attempts to continue the install.However, it fails on libraries/mongodb.rb:54 ->
because at the the time the search query runs, the first node in the replica set hasn't checked in with Chef yet so the data on the port isn't configured unless it's part of the role applied to the node before running chef-client with the wrapper cookbook attached.