puppet-mongodb icon indicating copy to clipboard operation
puppet-mongodb copied to clipboard

Mongo 3.6 database creation problem.

Open czapajew opened this issue 6 years ago • 1 comments

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 4.7.1
  • Ruby: ruby 2.1.9p490 (2016-03-30 revision 54437) [x86_64-linux]
  • Distribution: CentOS Linux release 7.3.1611 (Core)
  • Module version: 2.1.0

How to reproduce (e.g Puppet code you use)

class { 'mongodb::globals':
    manage_package_repo => false,
    manage_package      => true,
    manage_pidfile      => false,
    version             => '3.6.3-1.el7'
}
-> class {'::mongodb::client':
}
-> class { '::mongodb::server':
    bind_ip        => ['0.0.0.0'],
    dbpath         => '/opt/mongo',
    logpath        => '/opt/mongo/mongod.log',
    quiet          => false,
    auth           => true,
    restart        => false,
    create_admin   => true,
    admin_username => 'admin',
    admin_password => 'admin-password',
    admin_roles    => ['root'],
    store_creds    => true,
    slowms         => 5000,
    replset        => 'replset-name',
    storage_engine => 'wiredTiger',
    keyfile        => '/etc/mongod.key',
    key            => 'thisismykey'
}

What are you seeing

Error: Failed to apply catalog: 757: unexpected token at '{
	"databases" : [
		{
			"name" : "admin",
			"sizeOnDisk" : 147456,
			"empty" : false
		},
		{
			"name" : "config",
			"sizeOnDisk" : 20480,
			"empty" : false
		},
		{
			"name" : "local",
			"sizeOnDisk" : 430080,
			"empty" : false
		}
	],
	"totalSize" : 598016,
	"ok" : 1,
	"operationTime" : Timestamp(1521039021, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1521039021, 1),
		"signature" : {
			"hash" : BinData(0,"/DRm1gxEZjw9JUrKBA4MQjYUX+c="),
			"keyId" : "6532767491985244161"
		}
	}
}
'

What behaviour did you expect instead

No error

Output log

Debug: Connected to mongodb in 0.001244489 seconds.
Debug: Prefetching mongodb resources for mongodb_database
Debug: Executing: '/bin/mongo admin --quiet --host 127.0.0.1:27017 --eval load('/root/.mongorc.js'); printjson(db.getMongo().getDBs())'
Debug: Storing state
Debug: Stored state in 0.07 seconds
Error: Failed to apply catalog: 757: unexpected token at '{
	"databases" : [
		{
			"name" : "admin",
			"sizeOnDisk" : 147456,
			"empty" : false
		},
		{
			"name" : "config",
			"sizeOnDisk" : 20480,
			"empty" : false
		},
		{
			"name" : "local",
			"sizeOnDisk" : 425984,
			"empty" : false
		}
	],
	"totalSize" : 593920,
	"ok" : 1,
	"operationTime" : Timestamp(1521037711, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1521037711, 1),
		"signature" : {
			"hash" : BinData(0,"FRWHMhjGcgspM2BcnZXQJTrGNiE="),
			"keyId" : "6532767491985244161"
		}
	}
}
'
Debug: Dynamically-bound server lookup failed, falling back to report_server setting
Debug: Dynamically-bound port lookup failed; falling back to report_port setting

Any additional information you'd like to impart

I have found that mongo 3.6.3

printjson(db.getMongo().getDBs())

show different output than earlier versions: in 3.6.3 is:

{
	"databases" : [
		{
			"name" : "admin",
			"sizeOnDisk" : 200704,
			"empty" : false
		},
		{
			"name" : "config",
			"sizeOnDisk" : 20480,
			"empty" : false
		},
		{
			"name" : "local",
			"sizeOnDisk" : 442368,
			"empty" : false
		}
	],
	"totalSize" : 696320,
	"ok" : 1,
	"operationTime" : Timestamp(1521042451, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1521042451, 1),
		"signature" : {
			"hash" : BinData(0,"LvZA6qFyfPVoVSGqZlWDRf7XrBs="),
			"keyId" : NumberLong("6532767491985244161")
		}
	}
}

3.2 is:

{
    "databases" : [
        {
            "name" : "admin",
            "sizeOnDisk" : 200704,
            "empty" : false
        },
        {
            "name" : "local",
            "sizeOnDisk" : 7976722432,
            "empty" : false
        }
    ],
    "totalSize" : 320729784320,
    "ok" : 1
}

Change in puppet/modules/mongodb/lib/puppet/provider/mongodb_database/mongodb.rb as below helps.

- dbs = JSON.parse mongo_eval('printjson(db.getMongo().getDBs())')
+ dbs = JSON.parse mongo_eval('printjson(db.getMongo().getDBs())').gsub!(%r{\w+\((\d+).+?\)}, '\1')

czapajew avatar Mar 14 '18 15:03 czapajew

can confirm this bug is present since mongo 3.6.x the output for the command in mongo gives an invalid json which errors out the json.parse.

TomRitserveldt avatar Jun 06 '18 08:06 TomRitserveldt