Monday, 19 October 2015

Vagrant - Puppet Java development environment setup


Vagrant:-

Vagrant is an open-source (MIT) tool for building and managing virtualised development environments

Simply put, Vagrant makes it really easy to work with virtual machines. According to the Vagrant docs:

"If you’re a designer, Vagrant will automatically set everything up that is required for that web app in order for you to focus on doing what you do best: design. Once a developer configures Vagrant, you don’t need to worry about how to get that app running ever again. No more bothering other developers to help you fix your environment so you can test designs. Just check out the code, vagrant up, and start designing."

Puppet:-

Puppet is a configuration management tool that is extremely powerful in deploying, configuring, managing, maintaining, a server machine.


Librarian Puppet:-

Librarian-puppet is a project by the amazing Tim Sharpe to take Librarian, a general reimplementation of Bundler, and provide an implementation for the Puppet ecosystem. It has support for installing Puppet modules from the Puppet Forge as well as Github, and provides any number of other features like version locking of installed modules.

Simply, we can have a virtual box and vagrant setup and we can write shell scripts/batch files to install softwares based on the development environment.

If we use puppet and librarian puppet along with with virtual box we only need to concentrate on setting up vagrant, puppet, librarian puppet rest will be taken care of by puppet module itself.

Virtual Box Setup

Download virtual box from here [https://www.virtualbox.org/wiki/Downloads] for the environment you are working on. Once downloaded follow the instructions to install

If we want to work with vagrant we must have a virtual box.

Vagrant Setup

With virtual box installed we are ready to go ahead with vagrant installation. 
Download vagrant from here [https://www.vagrantup.com/downloads.html]. Once downloaded follow the instructions to install.

Puppet Setup

You can write a environment specific shell script/batch file to install puppet manually or shell script could be executed from Vargrant file itself while executing the command  $ vagrant up For simplicity lets assume we will manually execute the shell script/batch file to install puppet.


Librarian Puppet Setup

You can write a environment specific shell script/batch file to install librarian puppet manually or shell script could be executed from Vargrant file itself while executing the command  $ vagrant up For simplicity lets assume we will manually execute the shell script/batch file to install librarian puppet.

Now we have a virual box, vagrant, puppet, librarian puppet installed.


Lets create our First Instance 

$ mkdir my_first_instance
$ cd my_first_instance
$ vagrant init precise32  http://files.vagrantup.com/precise32.box

once successfully executed it will create Vagrantfile in the empty directory created above with some default settings. Now execute 

$vagrant up

Wait for few minutes, this will start the virtual box [ubuntu machine]. Now using ssh we can interact with the virtual box

$vagrant ssh 

[
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/
New release '14.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2
vagrant@precise32:~$  ]

$vagrant ssh exit  - command to exit virtual box

$vagrant suspend -  command to stop virtual machine

$vagrant destroycommand to remove the setup

Development Environment Setup

At this point we have a virtual box up and running, vagrant setup, puppet and librarian puppet installed.

$ cd my_first_instance
$ mkdir puppet
$ cd puppet
$ mkdir  manifests
$ mkdir modules
$ touch Puppetfile
$ cd manifests
$ touch default.pp

the Puppetfile will have the modules required for your development and default.pp file will have the dependencies.

Sample Puppetfile
[forge "http://forge.puppetlabs.com"

mod "puppetlabs/stdlib", "3.2.1"
mod "puppetlabs/apt", "1.5.0"
mod "puppetlabs/mysql", "2.2.3"
#mod "puppetlabs/rabbitmq", "5.0.0"
mod "thomasvandoren/redis", "0.10.0"
mod "jbussdieker/memcached"
mod "puppetlabs/git"
mod "tylerwalts/jdk_oracle"
mod "gini/gradle"]

Puppet modules could be found executing the command $ sudo puppet module search {mysql}
In default.pp file under manifests define the dependencies like -

# --- MySQL --- #

class { '::mysql::server':
 root_password => 'foo'
}

Once defined go to puppet directory under parent directory [$ cd my_first_instance/puppet] and execute 
$ sudo librarian-puppet install - this will install modules under puppet directory
$ cd ..
$ vagrant reload --provision

Once provisioning has been successfully completed it will install the software module to virtual box. We can now login to vm and start using it.

Sample virtual box setup scripts are available here [https://github.com/badalb/vagrant-java]