sous-chefs / sc-mongodb

Development repository for the sc-mongodb cookbook
https://supermarket.chef.io/cookbooks/sc-mongodb
Apache License 2.0
75 stars 93 forks source link

ERROR: mongodb_user[admin] (mongodb::user_management line 14) had an error: NameError: uninitialized constant Mongo::MongoClient #85

Closed mgarciadelojo closed 8 years ago

mgarciadelojo commented 8 years ago

Hi guys!

I am struggling to make mongodb work. Using the configuration below with no success:

environment:

override_attributes(
  :mongodb => {
    :install_method => 'mongodb-org',
    :config => { :auth => true },
    :admin => {
      :username => 'admin',
      :password => 'password'
    },
    :authentication => {
      :username => 'admin',
      :password => 'password'
    },
    :users => [
      {
        :username => "myuser",
        :password => "password",
        :roles    => ["dbOwner"],
        :database => "mydatabase",
      }
    ]
  }
)

role:

all_env = [
  "role[base]",
  "recipe[mongodb]",
  "recipe[mongodb::user_management]"
]

run_list(all_env)

But when running the project locally using Vagrant I get this error:

==> default: /opt/chef/embedded/apps/chef/lib/chef/application.rb:60:in `run'
==> default: /opt/chef/embedded/apps/chef/bin/chef-solo:25:in `<top (required)>'
==> default: /usr/bin/chef-solo:53:in `load'
==> default: /usr/bin/chef-solo:53:in `<main>'
==> default: [2015-08-14T22:46:45+00:00] ERROR: mongodb_user[admin] (mongodb::user_management line 14) had an error: NameError: uninitialized constant Mongo::MongoClient
==> default: [2015-08-14T22:46:45+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Could anyone help me, please? I am a little stuck at this point and don't know what to do. I am pretty sure there is something I am not doing well but can't figure out what.

Thanks!

luishdez commented 8 years ago

It's a clean VM? What distro are you using?

Take a look to this repo that I've made for testing https://github.com/luishdez/mongodb-cookbook-playground It's using vagrant and client auth.

mgarciadelojo commented 8 years ago

Yes, it is. I am currently using Ubuntu Trusty 64.

Ok, i'll give it a try, but do you know what's going on here? It's a little bit frustrating afterwards.

Thanks

On 17 Aug 2015, at 22:29, Luis Hdez notifications@github.com wrote:

It's a clean VM? What distro are you using?

Take a look to this repo that I've made for testing https://github.com/luishdez/mongodb-cookbook-playground It's using vagrant and client auth.

— Reply to this email directly or view it on GitHub.

luishdez commented 8 years ago

It's something related to Ruby and the Mongo Gem. Check this related issue https://github.com/chef-brigade/mongodb-cookbook/issues/41

luishdez commented 8 years ago

@mgarciadelojo have you solved your issue?

mgarciadelojo commented 8 years ago

@luishdez It seems the error is not showing up again, but chef is not creating the database anymore.

mgarciadelojo commented 8 years ago

In my environment development.rb I have:

override_attributes(
  :mongodb => {
    :install_method => "10gen",
    :config => { :auth => true },
    :admin => {
      :username => "admin",
      :password => "password",
      :roles    => ["root", "userAdminAnyDatabase", "dbAdminAnyDatabase"],
      :database => "admin"
    },
    :users => [
      {
        :username => "myuser",
        :password => "password",
        :roles    => ["dbOwner", "readWrite"],
        :database => "mydatabase"
      }
    ]
  }
)

I tried to replicate the same code you created in this repo: https://github.com/luishdez/mongodb-cookbook-playground with no luck...

Do you have any idea about what I am doing wrong? Thanks in advance

mgarciadelojo commented 8 years ago

@luishdez any idea? I am a bit frustrated with this stuff.

luishdez commented 8 years ago

Ok let's try this:

cookbook "mongodb",
  :git => "https://github.com/chef-brigade/mongodb-cookbook.git",
  :ref => "master"
mgarciadelojo commented 8 years ago

I activated only this cookbook, but after vagrant is up, I enter the machine and run the mongo command like so:

vagrant@local:~$ mongo
MongoDB shell version: 2.6.11
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
> show dbs
admin  0.078GB
local  0.078GB
>

Does it mean that users aren't being created? I think in mongo, when you create an user you have to specify the database in order to give him permissions.

I checked if the cookbook installed the mongo gem as you requested, but the mongo_gem recipe didn't work.

vagrant@local:~$ gem query --local

*** LOCAL GEMS ***
vagrant@local:~$ 

I tried to install the gem manually (gem install mongo -v 1.12.3) into vagrant and run a vagrant provision as well with no luck.

Here is my Berksfile:

source 'https://supermarket.chef.io'

# Base Role
cookbook 'apt', '~> 2.8.2'
cookbook 'git', '~> 4.3.3'
cookbook 'locale', '~> 1.0.2'
cookbook 'build-essential', '~> 2.2.3'
cookbook 'sudo', '~> 2.7.2'
cookbook 'users', '~> 1.8.2'

# Database
cookbook 'mongodb',
  :git => 'https://github.com/chef-brigade/mongodb-cookbook.git',
  :ref => 'master'

My Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "ubuntu/trusty64"

  # The url from where the 'config.vm.box' box will be fetched if it
  # doesn't already exist on the user's system.
  # config.vm.box_url = "http://files.vagrantup.com/trusty64.box"

  # The hostname the machine should have. Defaults to nil. If nil, Vagrant
  # won't manage the hostname. If set to a string, the hostname will be set
  # on boot.
  config.vm.hostname = "local.runator"

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 27017, host: 27017

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder "src", "/var/www", nfs: true

  # Configure other VM settings
  config.vm.provider "virtualbox" do |vb|
    vb.name = config.vm.hostname
    vb.memory = "1024"
  end

  config.ssh.password = "vagrant"

  # Enable provisioning using chef-solo
  config.vm.provision "chef_solo" do |chef|
    chef.log_level = "debug"
    chef.version = "12.4.0"

    chef.cookbooks_path = ["cookbooks", "berks-cookbooks"]
    chef.data_bags_path = "data_bags"
    chef.environments_path = "environments"
    chef.roles_path = "roles"

    chef.environment = "development"
    chef.add_role "database"
  end
end

Here my database.rb role:

name "database"
description "Database Server role"

override_attributes(
  "mongodb" => {
    "install_method" => "10gen",
    "config" => { "auth" => true },
    "admin" => {
      "username" => "admin",
      "password" => "password",
      "roles"    => ["root", "userAdminAnyDatabase", "dbAdminAnyDatabase"],
      "database" => "admin"
    },
    "users" => [
      {
        :username => "myuser",
        :password => "password",
        :roles    => ["dbOwner", "readWrite"],
        :database => "mydatabase"
      }
    ]
  }
)

all_env = [
  "role[base]",
  "recipe[mongodb]",
  "recipe[mongodb::user_management]",
  "recipe[runator::database]"
]

run_list(all_env)

My development.rb environment is empty, so it has no configuration at all yet.

I still struggling with that, I'll notice you if I achieve some advance.

Thank you.

luishdez commented 8 years ago

Hi @mgarciadelojo I've updated https://github.com/luishdez/mongodb-cookbook-playground with your Ubuntu box and your cookbooks. I just remove your extra recipes and I had to change apt to 2.7.0 because librarian chef says there are conflicts. So I guess some dependencies have conflicts that doesn't allow to install the mongo gem.

unbunto-mongo

I'm closing this because I'm not able to reproduce it. Anyways if you continue with the trouble go to the slack group (check README) or mail me :)

lock[bot] commented 6 years ago

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.