How to setup a dev environment using Vagrant & Puppet (Part II)04 Apr 2014
This is a continuation of my previous post on how to get up and running with Vagrant.
Now let’s get more specific and see how we can install specific modules.
To install PostgreSQL I’ve chosen to use this module on GitHub. Let’s go ahead and add that as a submodule. Run this command from the git root folder:
git submodule add https://github.com/akumria/puppet-postgresql.git puppet/modules/postgresql
Also keep in mind, the destination directory should have the same name as the main module’s class. So in this case,
You can now add this module into your
puppet/manifests folder to start using it:
That’s the most basic way to get started. Although to make things easier, we should probably also add any databases or users that we will need. And if you plan to access PostgreSQL from your host machine, you will also need to open up the port and allow incoming traffic from the host.
So taking those things into consideration, here’s what it would end up looking like:
Finally in your
Vagrantfile, make sure you are forwarding that port to whichever port you want on your host machine:
config.vm.network :forwarded_port, guest: 5432, host: 5433
Now let’s take a look at how to go about installing Ruby. Instead of a package, we’ll just do this manually. First let’s defined a variable called
$as_vagrant. It’s a reusable command which will let us basically run other commands as the vagrant user:
$as_vagrant = 'sudo -u vagrant -H bash -l -c'
We also need to make sure, curl is installed:
Now we can install RVM (note the dependency on the curl package):
Next up, install Ruby 2.0.0 (note the dependency on our previous
Finally, install Bundler:
For python I’ve chosen to use this module which makes it very easy to install.
Let’s add that as a submodule:
git submodule add https://github.com/stankevich/puppet-python.git puppet/modules/python
Now all you have to do is add this declaration:
You can checkout more params/arguments on their GitHub page.
If you’d like to learn more about creating and consuming modules, I would also recommend checking out Erika Heidi’s site for in-depth blog posts and talks.
Finally you are now ready to fire up your new Vagrant machine. Just run the following commands:
$ vagrant up $ vagrant provision $ vagrant ssh
You can now just go to the /vagrant folder where you should see the project folder that you just cloned. This folder is shared with your host so you can open your favorite editor on the host and start hacking away.
New version of Vagrant also includes the ability to Share, Distribute and Discover your Vagrant boxes. I have been sharing my Vagrant machine using ngrok, a utility that I mentioned in my previous post about useful web development tools. With the release of vagrant share, you could skip that and just do:
vagrant share --ssh
That will create a random shareable web URL such as http://hulking-chameleon-3934.vagrantshare.com which would point to your Vagrant instance.
This is very handy for sharing results with co-workers or remote debugging. On the flip side, you can also SSH into other Vagrant machines :
vagrant connect --ssh hulking-chameleon-3934
More details on how this works on their site.
That’s it, I think I’ve covered the basics. Let me know if you’d like to me cover anything else.