几个月来,我一直在成功使用 mongodb 食谱创建用户帐户,但最近发生了一些变化,我不知道它是什么。默认配方完成且没有错误,并且成功安装了 mongodb 服务器,但是 user_management 配方失败并出现错误NameError: uninitialized constant Mongo::MongoClient
。
这是在具有 chef 版本 11.10 和 Berkshelf 版本 3.2.0 的 AWS Opsworks 环境中。
伯克斯文件
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
谢谢你的帮助!
根据我在拉取请求384中看到的修改,我修改了食谱以将 'mongo' 和 'bson_ext' 版本都锁定为 1.x,并为我修复了它(悲观地允许 1.x 不起作用)。
属性/default.rb
食谱/user_management.rb
修改后的食谱可在此处获得。请注意,由于 gem 被锁定在特定版本,这不是永久修复。
希望官方食谱的维护者能有时间赶上所有积压的 PR。
更新(2015 年 10 月 5 日):chef-brigade 勇敢地维护了这本食谱,并开始解决 PR 的积压问题。您可以从chef-brigade repo 获取更新的食谱。