Today I created a virtual machine for mongoDB. It’s a long time since I worked last time with it. So I wanted a generic machine that I can start, stop or destroy without the need to reinstall it everytime by hand. Sounds like vagrant and ansible 😉
Get our hands dirty
As mentioned, I will use a Vagrant base image of Ubuntu 14.04 and provision it with ansible to install and configure mongoDB. Since I don’t like to use vagrant portmapping for all port that I may be using, I like to use the vagrant plugin ‘vagrant-hostsupdater’.
- Install vagrant from here.
For example on debian or ubuntu:
1sudo dpkg -i ~/Downloads/vagrant*.deb
- Install vagrants hostsupdater plugin:
1vagrant plugin install vagrant-hostsupdater
- Install git and ansible on your machine
1sudo apt-get install ansible git
- Clone my git repository and change to the directory:
1git clone email@example.com:hauckd/vagrant-ansible-mongodb.git && cd vagrant-ansible-mongodb
- Just run the vagrant machine
- That’s it!
After the startup and the provisioning of the vagrant machine finished you either can ssh into the vagrant machine to play with your mongodb instance
or connect directly to mongodb with
That’s the cool thing about the hostsupdater plugin, you can interact with the machine just like a real host, just give it a hostname in the Vagrantfile.
So after a couple of minutes you are up and running and can begin your journey with a great noSQL database management system.
Don’t forget to follow me on twitter or subscribe to the newsletter on the left site to recieve the latest posts. Of course you can give me a few stars on github 🙂