edelight / chef-mongodb

MongoDB Chef cookbook
https://community.opscode.com/cookbooks/mongodb
Apache License 2.0
362 stars 3 forks source link

Support authenticating as admin #54

Open jelder opened 12 years ago

jelder commented 12 years ago

Replica set configuration fails when auth is enabled.

INFO: template[/etc/default/mongodb] sending restart action to service[mongodb] (delayed)
INFO: Processing service[mongodb] action restart (mongodb::replicaset line 140)
INFO: service[mongodb] restarted
INFO: service[mongodb] sending create action to ruby_block[config_replicaset] (delayed)
INFO: Processing ruby_block[config_replicaset] action create (mongodb::replicaset line 166)
WARN: Could not connect to database: 'localhost:27017'
INFO: ruby_block[config_replicaset] called
0xAhmed commented 11 years ago

+1

henryoswald commented 10 years ago

+1 does anyone have a good solution to this yet?

josephholsten commented 10 years ago

I'm sorry for the delay. The cause of this is somewhere deep inside the 190 lines of Mongodb.configure_replicaset. The original authors have no longer contribute to this cookbook, and I'm usually too feeble minded to grok all that, so I shy away from these tickets in fear.

I can see that your issue is coming from line 47, but I don't really know much about this library.

Oh, it looks like our Mongo::Connection is being deprecated in favor of Mongo::Client. joy.

Looks like we're going to need to #add_auth to the connection.

josephholsten commented 10 years ago

oh joy, we also set up multiple connections.

josephholsten commented 10 years ago

I haven't added this to #221 yet, but I'll just leave this comment to remind me that this ticket is related.

pauzed commented 10 years ago

For me, I've been dropping an auth command after connection strings, like: https://github.com/edelight/chef-mongodb/blob/master/libraries/mongodb.rb#L42

Mine looks along the lines of:

if node[:mongodb][:config][:auth] connection["admin"].authenticate(mongo_bag["admin"]["username"], mongo_bag["admin"]["password"]) end

mongo_bag is simply an encrypted databag im storing credentials in. This has been working pretty well for me in all of my replicasets.