几个月来,我一直在使用 mongodb cookbook 成功创建用户帐户,但最近发生了一些变化,我不知道是什么原因。默认配方无错误完成,mongodb 服务器安装成功,但是 user_management 配方失败并出现错误NameError: uninitialized constant Mongo::MongoClient
。
这是在 AWS Opsworks 环境中,其中 chef 版本为 11.10,Berkshelf 版本为 3.2.0。
伯克斯菲尔
source "https://supermarket.chef.io"
cookbook 'mongodb', '~> 0.16.1', github: 'edelight/chef-mongodb'
下面是我在该层中使用的自定义 json 的 mongodb 部分:
"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"
}
]
},
这是我执行 mongodb::user_management 配方时的 opsworks 日志。
[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)
更新:
当我将 chef.io cookbook 的最新提交更新为“悲观地允许 1.X mongo gem”时,我得到了同样的错误:
伯克斯菲尔
source "https://supermarket.chef.io"
cookbook 'mongodb', git: 'https://github.com/bellpeterm/chef-mongodb.git', ref: '45cdb7177a5f6e9b59dea2ec8e057321114e8a3c'
Opsworks 日志:
[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
感谢您的帮助!
答案1
根据我在拉取请求中看到的修改384我修改了食谱,将“mongo”和“bson_ext”版本锁定为 1.x,这为我解决了问题(悲观地说,允许 1.x 不起作用)。
属性/默认.rb
# install the mongo and bson_ext ruby gems at compile time to make them globally available
# TODO: remove bson_ext once mongo gem supports bson >= 2
default['mongodb']['ruby_gems'] = {
- :mongo => nil,
- :bson_ext => nil
+ :mongo => '1.12',
+ :bson_ext => '1.12'
}
食谱/用户管理.rb
-chef_gem 'mongo'
+include_recipe 'mongodb::mongo_gem'
users = []
admin = node['mongodb']['admin']
修改后的食谱现已可用这里。请注意,由于宝石被锁定在特定版本,因此这不是永久的修复。
希望官方食谱的维护者能花一些时间来处理所有积压的 PR。
更新(2015 年 10 月 5 日):chef-brigade 勇敢地接手了这本食谱的维护工作,并开始处理 PR 积压问题。您可以从厨师大队回購。