I have been using the mongodb cookbook successfully to create user accounts for months but recently something has changed and I can't figure out what it is. The default recipe completes without errors and the mongodb server is installed successfully, however, the user_management recipe fails with the error NameError: uninitialized constant Mongo::MongoClient
.
This is in an AWS Opsworks environment with chef version 11.10 and Berkshelf version 3.2.0.
Berksfile
source "https://supermarket.chef.io"
cookbook 'mongodb', '~> 0.16.1', github: 'edelight/chef-mongodb'
Here is the mongodb portion of the custom json I use in the layer:
"mongodb": {
"dbconfig_file": "/etc/mongod.conf",
"sysconfig_file": "/etc/default/mongod",
"default_init_name": "mongod",
"instance_name": "mongod",
"admin": {
"username": "admin",
"password": "xxxxx"
},
"config": {
"auth": true,
"bind_ip": "0.0.0.0",
"port": "27017",
"logpath": "/var/log/mongo/mongod.log",
"dbpath": "/var/lib/mongo"
},
"authentication": {
"username": "admin",
"password": "xxxxx"
},
"users": [
{
"username": "mongodb-dba1",
"password": "xxxxx",
"roles": [
"root"
],
"database": "admin"
},
{
"username": "mongodb-rw1",
"password": "xxxxx",
"roles": [
"readWrite"
],
"database": "apis_cache"
},
{
"username": "mongodb-r1",
"password": "xxxxx",
"roles": [
"read"
],
"database": "apis_cache"
},
{
"username": "admin",
"password": "xxxxx",
"roles": [
"userAdminAnyDatabase",
"dbAdminAnyDatabase"
],
"database": "admin"
}
]
},
Here is the opsworks log when I execute the mongodb::user_management recipe.
[2015-04-14T13:33:31+00:00] INFO: Processing chef_gem[mongo] action install (mongodb::user_management line 1)
[2015-04-14T13:33:32+00:00] WARN: Cloning resource attributes for mongodb_user[admin] from prior resource (CHEF-3694)
[2015-04-14T13:33:32+00:00] WARN: Previous mongodb_user[admin]: /var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/recipes/user_management.rb:14:in `block in from_file'
[2015-04-14T13:33:32+00:00] WARN: Current mongodb_user[admin]: /var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/recipes/user_management.rb:14:in `block in from_file'
[2015-04-14T13:33:32+00:00] INFO: Processing template[/etc/hosts] action create (opsworks_stack_state_sync::hosts line 3)
[2015-04-14T13:33:32+00:00] INFO: Processing template[/etc/motd.opsworks-static] action create (opsworks_stack_state_sync::motd line 1)
[2015-04-14T13:33:32+00:00] INFO: Processing chef_gem[mongo] action install (mongodb::user_management line 1)
[2015-04-14T13:33:32+00:00] INFO: Processing mongodb_user[admin] action add (mongodb::user_management line 14)
================================================================================
Error executing action `add` on resource 'mongodb_user[admin]'
================================================================================
NameError
---------
uninitialized constant Mongo::MongoClient
Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/providers/user.rb:62:in `retrieve_db'
/var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/providers/user.rb:9:in `add_user'
/var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/providers/user.rb:71:in `block in class_from_file'
Resource Declaration:
---------------------
# In /var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/recipes/user_management.rb
14: mongodb_user user['username'] do
15: password user['password']
16: roles user['roles']
17: database user['database']
18: connection node['mongodb']
19: action :add
20: end
21: end
Compiled Resource:
------------------
# Declared in /var/lib/aws/opsworks/cache.stage2/cookbooks/mongod/recipes/user_management.rb:14:in `block in from_file'
mongodb_user("admin") do
action [:add]
retries 0
retry_delay 2
cookbook_name "mongodb"
recipe_name "user_management"
password "xxxxx"
roles ["userAdminAnyDatabase", "dbAdminAnyDatabase"]
database "admin"
connection {"client_roles"=>[], "cluster_name"=>nil, "shard_name"=>"default", "replica_arbiter_only"=>false, "replica_build_indexes"=>true, "replica_hidden"=>false, "replica_slave_delay"=>0, "replica_priority"=>1, "replica_tags"=>{}, "replica_votes"=>1, "auto_configure"=>{"replicaset"=>true, "sharding"=>true}, "configserver_url"=>nil, "root_group"=>"root", "user"=>"mongodb", "group"=>"mongodb", "init_dir"=>"/etc/init/", "init_script_template"=>"debian-mongodb.upstart.erb", "sysconfig_file"=>"/etc/default/mongod", "sysconfig_file_template"=>"mongodb.sysconfig.erb", "dbconfig_file_template"=>"mongodb.conf.erb", "dbconfig_file"=>"/etc/mongod.conf", "package_name"=>"mongodb", "package_version"=>nil, "default_init_name"=>"mongod", "instance_name"=>"mongod", "install_method"=>"distro", "is_replicaset"=>nil, "is_shard"=>nil, "is_configserver"=>nil, "reload_action"=>"restart", "apt_repo"=>"ubuntu-upstart", "template_cookbook"=>"mongodb", "key_file_content"=>nil, "ruby_gems"=>{"mongo"=>nil, "bson_ext"=>nil}, "config"=>{"port"=>"27017", "bind_ip"=>"0.0.0.0", "logpath"=>"/var/log/mongo/mongod.log", "logappend"=>true, "fork"=>false, "dbpath"=>"/var/lib/mongo", "nojournal"=>false, "rest"=>false, "smallfiles"=>false, "oplogSize"=>nil, "replSet"=>nil, "auth"=>true}, "mms_agent"=>{"api_key"=>nil, "package_url"=>"https://mms.mongodb.com/download/agent/%{agent_type}/mongodb-mms-%{agent_type}-agent", "monitoring"=>{"version"=>"2.2.0.70-1", "mmsApiKey"=>nil, "mmsBaseUrl"=>"https://mms.mongodb.com", "configCollectionsEnabled"=>true, "configDatabasesEnabled"=>true, "throttlePassesShardChunkCounts"=>10, "throttlePassesDbstats"=>20, "throttlePassesOplog"=>10, "disableProfileDataCollection"=>false, "disableGetLogsDataCollection"=>false, "disableLocksAndRecordStatsDataCollection"=>false, "enableMunin"=>true, "useSslForAllConnections"=>false, "sslRequireValidServerCertificates"=>false}, "backup"=>{"version"=>"2.1.0.106-1", "mmsApiKey"=>nil, "mothership"=>"api-backup.mongodb.com", "https"=>true, "sslRequireValidServerCertificates"=>false}, "user"=>"mongodb-mms-agent", "group"=>"mongodb-mms-agent"}, "sysconfig"=>{"DAEMON"=>"/usr/bin/$NAME", "DAEMON_USER"=>"mongodb", "DAEMON_OPTS"=>"--config /etc/mongod.conf", "CONFIGFILE"=>"/etc/mongod.conf", "ENABLE_MONGODB"=>"yes", "DAEMONUSER"=>"mongodb", "ENABLE_MONGOD"=>"yes", "ENABLE_MONGO"=>"yes"}, "ulimit"=>{"fsize"=>"unlimited", "cpu"=>"unlimited", "as"=>"unlimited", "nofile"=>64000, "rss"=>"unlimited", "nproc"=>32000}, "admin"=>{"username"=>"admin", "password"=>"xxxxx", "roles"=>["userAdminAnyDatabase", "dbAdminAnyDatabase"], "database"=>"admin"}, "users"=>[{"username"=>"mongodb-dba1", "password"=>"xxxxx", "roles"=>["root"], "database"=>"admin"}, {"username"=>"mongodb-rw1", "password"=>"xxxxx", "roles"=>["readWrite"], "database"=>"apis_cache"}, {"username"=>"mongodb-r1", "password"=>"xxxxx", "roles"=>["read"], "database"=>"apis_cache"}, {"username"=>"admin", "password"=>"xxxxx", "roles"=>["userAdminAnyDatabase", "dbAdminAnyDatabase"], "database"=>"admin"}], "save-state"=>"false", "restore-state"=>"false", "monit"=>"true", "pid_file"=>"/var/lib/mongo/mongod.lock", "start_command"=>"/usr/bin/env service mongod start", "stop_command"=>"/usr/bin/env service mongod stop", "authentication"=>{"username"=>"admin", "password"=>"xxxxx"}}
username "admin"
end
[2015-04-14T13:33:32+00:00] INFO: Running queued delayed notifications before re-raising exception
[2015-04-14T13:33:32+00:00] ERROR: Running exception handlers
[2015-04-14T13:33:32+00:00] ERROR: Exception handlers complete
[2015-04-14T13:33:32+00:00] FATAL: Stacktrace dumped to /var/lib/aws/opsworks/cache.stage2/chef-stacktrace.out
[2015-04-14T13:33:32+00:00] ERROR: mongodb_user[admin] (mongodb::user_management line 14) had an error: NameError: uninitialized constant Mongo::MongoClient
[2015-04-14T13:33:32+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
UPDATE:
I get the same error with the latest commit of chef.io cookbook updated to "pessimistically allow 1.X mongo gem":
Berksfile
source "https://supermarket.chef.io"
cookbook 'mongodb', git: 'https://github.com/bellpeterm/chef-mongodb.git', ref: '45cdb7177a5f6e9b59dea2ec8e057321114e8a3c'
Opsworks log:
[2015-04-14T19:19:07+00:00] INFO: Processing chef_gem[mongo] action install (mongodb::mongo_gem line 20)
[2015-04-14T19:19:07+00:00] INFO: Installing chef-gem mongo ~> 1.12
[2015-04-14T19:19:16+00:00] INFO: Successfully installed bson-1.12.1
Successfully installed mongo-1.12.1
2 gems installed
[2015-04-14T19:19:16+00:00] INFO: Processing chef_gem[bson_ext] action install (mongodb::mongo_gem line 20)
[2015-04-14T19:19:19+00:00] INFO: Installing chef-gem bson_ext = 1.12.1
[2015-04-14T19:19:24+00:00] INFO: Building native extensions. This could take a while...
Successfully installed bson_ext-1.12.1
1 gem installed
[2015-04-14T19:19:24+00:00] WARN: Cloning resource attributes for mongodb_user[admin] from prior resource (CHEF-3694)
[2015-04-14T19:19:24+00:00] WARN: Previous mongodb_user[admin]: /var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/recipes/user_management.rb:14:in `block in from_file'
[2015-04-14T19:19:24+00:00] WARN: Current mongodb_user[admin]: /var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/recipes/user_management.rb:14:in `block in from_file'
[2015-04-14T19:19:24+00:00] INFO: Processing template[/etc/hosts] action create (opsworks_stack_state_sync::hosts line 3)
[2015-04-14T19:19:24+00:00] INFO: Processing template[/etc/motd.opsworks-static] action create (opsworks_stack_state_sync::motd line 1)
[2015-04-14T19:19:24+00:00] INFO: Processing package[gcc] action nothing (mongodb::mongo_gem line 3)
[2015-04-14T19:19:24+00:00] INFO: Processing package[libsasl2-dev] action nothing (mongodb::mongo_gem line 15)
[2015-04-14T19:19:24+00:00] INFO: Processing chef_gem[mongo] action install (mongodb::mongo_gem line 20)
[2015-04-14T19:19:24+00:00] INFO: Processing chef_gem[bson_ext] action install (mongodb::mongo_gem line 20)
[2015-04-14T19:19:24+00:00] INFO: Processing mongodb_user[admin] action add (mongodb::user_management line 14)
================================================================================
Error executing action `add` on resource 'mongodb_user[admin]'
================================================================================
NameError
---------
uninitialized constant Mongo::MongoClient
Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/providers/user.rb:62:in `retrieve_db'
/var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/providers/user.rb:9:in `add_user'
/var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/providers/user.rb:71:in `block in class_from_file'
Resource Declaration:
---------------------
# In /var/lib/aws/opsworks/cache.stage2/cookbooks/mongodb/recipes/user_management.rb
14: mongodb_user user['username'] do
15: password user['password']
16: roles user['roles']
17: database user['database']
18: connection node['mongodb']
19: action :add
20: end
21: end
Thanks for your help!