Skip to content

Instantly share code, notes, and snippets.

@yauh
Created July 9, 2014 12:18
Show Gist options
  • Save yauh/7f65a5c8d95a91e4a0ad to your computer and use it in GitHub Desktop.
Save yauh/7f65a5c8d95a91e4a0ad to your computer and use it in GitHub Desktop.
Ansible install mongo cluster
---
- hosts: mongodb
sudo: True
remote_user: droid
roles:
- role: mongo_mongod
mongod_datadir_prefix: "/data"
mongod_replication: true
mongod_port: 2701
mongod_repl_servers: ['mongo1', 'mongo2', 'mongo3' ]
mongod_repl_master: mongo1
mongod_replset_name: rs1
- role: mongo_mongoc
mongoc_datadir_prefix: "/data"
mongoc_port: 2800
mongoc_admin_pass: password
- role: mongo_mongos
mongos_keyfile_dir_prefix: "/data"
mongos_port: 2900
mongoc_port: 2800
mongoc_servers: ['mongo1', 'mongo2', 'mongo3']
mongos_chunk_size: 1
- role: mongo_shard
mongo_shard_list:
- replset_name: rs1
hostname: mongo1
port: 2701
- replset_name: rs2
hostname: mongo2
port: 2701
- replset_name: rs3
hostname: mongo3
port: 2701
mongos_port: 2900
mongoc_admin_pass: password
@yauh
Copy link
Author

yauh commented Jul 9, 2014

Running against Ubuntu 14.04 the playbook keeps failing on me during the shard role with the following:

TASK: [mongo_shard | Add the shard to the mongos] *****************************
failed: [192.168.2.211] => {"changed": true, "cmd": "/usr/bin/mongo localhost:2900/admin -u admin -p password /tmp/shard_init.js ", "delta": "0:00:00.038379", "end": "2014-07-09 14:21:30.163546", "rc": 1, "start": "2014-07-09 14:21:30.125167"}
stderr: exception: connect failed
stdout: MongoDB shell version: 2.4.10
connecting to: localhost:2900/admin
Wed Jul 9 14:21:30.159 Error: couldn't connect to server localhost:2900 at src/mongo/shell/mongo.js:147

@yauh
Copy link
Author

yauh commented Jul 9, 2014

After running the playbook again, all nodes went through without any errors. However, logging in was not possible:

root@mongo1:/home/droid# /usr/bin/mongo localhost:2900/ansible -u admin -p password
MongoDB shell version: 2.4.10
connecting to: localhost:2900/ansible
Wed Jul  9 14:36:05.498 Error: 13106 nextSafe(): { $err: "error creating initial database config information :: caused by :: can't find a shard to put new db on", code: 10185 } at src/mongo/shell/db.js:228
exception: login failed

@yauh
Copy link
Author

yauh commented Jul 9, 2014

mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" : ObjectId("53ba5354e715388cc3e88469")
}
shards:
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }

@yauh
Copy link
Author

yauh commented Jul 9, 2014

root@mongo1:/home/stephan# /usr/bin/mongo --port 2701 /tmp/repset_init.js
MongoDB shell version: 2.4.10
connecting to: 127.0.0.1:2701/test
{
"set" : "rs1",
"date" : ISODate("2014-07-09T13:18:45Z"),
"myState" : 4,
"members" : [
{
"_id" : 0,
"name" : "mongo1:2701",
"health" : 1,
"state" : 4,
"stateStr" : "FATAL",
"uptime" : 4099,
"optime" : Timestamp(1404719847, 1),
"optimeDate" : ISODate("2014-07-07T07:57:27Z"),
"self" : true
},
{
"_id" : 1,
"name" : "mongo2:2701",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 4094,
"optime" : Timestamp(1404717875, 1),
"optimeDate" : ISODate("2014-07-07T07:24:35Z"),
"lastHeartbeat" : ISODate("2014-07-09T13:18:45Z"),
"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
"pingMs" : 0
}
],
"ok" : 1
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment