-
Notifications
You must be signed in to change notification settings - Fork 5
Testing with Vagrant
Vagrant can be used to test these puppet manifests. This page explains how to use the same with any of the puppet manifests.
- Install vagrant. This needs Oracle Virtual Box to be installed.
- Download the OS image (box) of your choice. Most MOTECH implementations are on CentOS, download a CentOS box from either vagrant website or some other source.
Once the prerequisites are installed using vagrant is as simple as running this shell script <MOTECH_SCM_CHECKOUT_DIR>/vagrant-vm/bootstrap.sh which prints the instructions on how to use.
**** HELP ****
1) Make sure you are in vagrant-vm folder
2) Run: <sh bootstap.sh init /path/to/image.box /path/to/configuration.pp> This creates Vagrantfile and initiates vagrant
3) From with-in vagrant-vm execute vagrant up/halt/reload/package (http://tinyurl.com/d4ljaxm) to test your changes in motech-scm/puppet/modules or configuration.pp or Vagrantfile
4) Run: <sh bootstrap.sh clear> to delete extra created files and destroy vagrant
Typical usage of this tool will be to create a configuration.pp which will have all the declarations of puppet classes or constructs to setup your system configuration. The constructs in the configuration.pp will be based on the motech-scm/modules.
For example: If you want to test the activemq manifest in motech-scm/modules, all you have to do is create a configuration.pp and declare the activemq puppet resource construct and run bootstrap.sh with the configuration.pp
- The first parameter for bootstrap.sh is the base OS image (in box format). Vagrant will load this image in to the virtual box before running the puppet manifests.
- The second parameter is the complete path of the configuration.pp which is a puppet manifest which will have all declarations of puppet resources which you want to create or configure on the OS image loaded by vagrant.
This is a declaration of couchdb resource in a sample configuration.pp. When this file is given as a parameter to bootstrap.sh it will setup your environment such that vagrant could load the base OS image and installs the couchdb with the given configuration.
class { "couchdb" :
couchReplicationSourceMachine => "10.9.8.10",
couchDbs => "ananya",
couchInstallationMode => "withReplication",
couchVersion => "1.2.0-7.el6",
couchDatabaseDir => "/var/lib/couchdb",
}
./bootstrap.sh init /path/to/image.box /path/to/configuration.pp
This will setup your vagrant environment to load the given image and configure the loaded image with the given puppet manifest resources.
vagrant up
Loads the image given in the first step and configures it will all the puppet resources given in the configuration.pp in the first step.
vagrant ssh
With this command you can login to the loaded OS image via ssh session and verify if the resources you have defined in configuration.pp are created.
After the OS image is loaded and all the resources given in configuration.pp are created, if you want to add one more resource and test. For example if in the first run you have configured activemq and verified the same , now you want to install couchdb. How would you do it ?
Quite simple, follow these steps
- Logout of ssh session
- Update the configuration.pp with new resources (in the example quoted above, add couchdb construct to the configuration.pp)
- Run a command
vagrant reload
Why would you want to do this ? to share a image to others in a given state or to roll back to a known right state.
Run a command vagrant package while the image is loaded outside the ssh session. This creates a file named package.box in the current directory.
If you want to start from scratch with a different box or configuration.pp all you have to do is run a command ./bootstrap.sh clear which destroys the loaded image and clears your vagrant environment.