Find file
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (76 sloc) 3.71 KB

Vagrant plugin and puppet manifests for MongoDB

Creates (by default) 8 virtual machines based on Ubuntu Lucid (64bits).

  • 1x ReplicaSet (primary, secondary, arbiter) without authentication.
  • 1x ReplicaSet (primary, secondary, arbiter) with authentication.
  • 1x Standalone server without authentication.
  • 1x Standalone server with authentication.

The ReplicaSet servers will have their /etc/hosts synchronized among them.

All servers will retrieve and install the latest MongoDB from the official 10gen repository.

Several new Vagrant configurations are available in the Vagrantfile to configure a MongoDB replicaset, such as the servers priority to become primaries.

A new Vagrant comand is availalbe to initialize the replicaset based on the configuration in the Vagrantfile, and to create users for authenticated setup.


$ git clone
$ cd vagrant-mongodb

Boot up all servers

$ vagrant up # Will bootup *all 8 servers*

Or only bootup a normal ReplicaSet

$ vagrant up primary secondary tertiary # Will bootup only one ReplicaSet

To bootup ReplicaSet with authentication enabled

$ vagrant up primaryauth secondaryauth tertiaryauth # RS with auth

Don't want ReplicaSets? This will create a standalone MongoDB server

$ vagrant up standalone # Will bootup the standalone server

And this will create a standalone MongoDB server with authentication enabled

$ vagrant up standaloneauth # Standalone with auth

Initializing ReplicaSets

To initialize the ReplicaSet for the first time, type

$ vagrant mongo primary --init-replicaset


$ vagrant mongo primaryauth --init-replicaset

To initialize the ReplicaSet for the authenticated environment.

Creating users

To create a first time admin user on a standalone server run

$ vagrant mongo standaloneauth -c -u adm -p pass --db admin

or for ReplicaSet environment

$ vagrant mongo primaryauth -c -u adm -p pass --db admin

To create more users you have to authenticate using that admin user

$ vagrant mongo standaloneauth -c -u user -p mypass --db mydb --authuser adm --authpass pass --authdb admin


The ReplicaSets are configured using the hostnames defined in the Vagrantfile. I recommend you add all these hosts to your local /etc/hosts (the servers themselves already have).

By default the following hostnames and IPs are used primaryauth secondaryauth tertiaryauth standaloneauth.local standaloneauth primary secondary tertiary standalone.local standalone

Thats it folks!

And there we go! Now you have a full MongoDB replicaset running in its own virtualized network, and all of the servers are running on the default ports. To connect to MongoDB, just fire up your favorite driver and connect :)

Fixing my mess?

This is the first time I have ever created a puppet module, puppet manifest, vagrant plugin or written Ruby code at all. There is very likely something could have been done better or prettier. I would love it if you forked this repo and applied your skillz cleaning things up.

Everything should work out of the box though :)


  • MongoDB Sharded environment
  • mongobride support
    • vagrant mongo command to tune mongobridge
    • Configuration settings
  • Split the vagrant mongo command to simplify creating users
  • Automatically initialize ReplicaSets when all RS vms have booted up