A quick introduction on how I use vagrant for developing my puppet manifests/modules/. You can almost certain also use this for other purposes. In general, this will get you up to speed fast!
We will quickly go over installation and/or updating and maybe even removing an old version using ruby gems.
Furthermore: adding a vagrant box and preparing a project to develop a puppet module (or something of the likes).
Installation
Installation is pretty simple. Make sure you have ruby (and ruby gems) installed and run
[user@hostname ~]$ gem install vagrant
Also make sure you have the proper virtualbox version installed. Check the website (http://vagrantup.com/docs/getting-started/index.html) on what version is required.
Updating
These commands should be performed as root or add sudo if you want the gems to be installed for all users.
If you want to install a gem as a user, make sure you add the -n <folder>
switch. This allows you to specify where a gem should install its executables. I use -n ~/.local/bin
whenever I install something as a user (development versions for example). Make sure to add the folder to your PATH for comfort.
Checking locally installed versions (optional but as a bonus!)
Local version:
[user@hostname ~]$ gem list vagrant
Remote versions available:
[user@hostname ~]$ gem list -r vagrant
Update the gem
[user@hostname ~]$ gem update vagrant
Removing old versions
Before removing a gem (any gem), always check if it was not installed by a package.
[user@hostname ~]$ gem list -d vagrant
Gems that are installed using gem will be in a /usr/local/lib*
dir structure. Gems installed by a package are in /usr/lib*
.
To remove a specific version:
[user@hostname ~]$ gem uninstall -v 0.7.5 vagrant
Getting started with vagrant
Add a box to your vagrant installation
Adding a box is as simple as:
[user@hostname ~]$ vagrant box add <boxname> <box path or url>
A box can be a local file, a remote file, …
For example:
[user@hostname ~]$ vagrant box add centos-5.7 \ http://packages.vstone.eu/vagrant-boxes/centos-5.7-64bit-puppet-vbox.4.1.4.box
Boxes are saved in ~/vagrant.d/boxes/. If you want them stored somewhere else on your disk, just remove the boxes folder and create a symlink to where whatever folder you prefer.
Creating a vagrant environment
Check what boxes you have available:
[user@hostname ~]$ vagrant box list centos-5.7-64bit
## create your 'project' structure. [user@hostname ~]$ mkdir -p example/{manifests,modules} [user@hostname ~]$ cd example [user@hostname ~/example]$ vagrant init <boxname>
You can also run vagrant init
without arguments in which case the box called ‘base’ will be used. Adjusting the box to use can be done by altering the line:
config.vm.box = "centos-5.7-64bit" |
Setting up your environment
Using puppet
Before we get really started, we need to adjust our Vagrant file a bit. Uncomment or add the following sections:
config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.module_path = "modules" puppet.manifest_file = "init.pp" end |
This defines our module directory and our manifests folder. Puppet will run the init.pp (located in manifests folder) after booting the machine.
Shared folders
In some cases, it might also be useful to share an extra folder between your vm and machine.
config.vm.share_folder "some_name", "/mnt/on/vm/", "/local/path/to/files" |
Tweaking your environment
If you are a vim user and have enabled modeline support:
[user@hostname ~/example]$ echo '# vim: set filetype=ruby : #' >> Vagrantfile
Now is also a good time to introduce some version control. git is perfect for the job:
[user@hostname ~/example]$ git init Initialized empty Git repository in /home/user/example/.git/
Starting up
Starting your vm is as easy as:
[user@hostname ~/example]$ vagrant up
This will take some time. Vagrant copies (imports) the base box and starts the vm. The disk of the vm will be located in the ‘Default Machine Folder’. Sometimes its useful to tweak this location a bit. Use the VirtualBox GUI for this.
After booting, the init.pp puppet manifest will be run.
Accessing your machine
[user@hostname ~/example]$ vagrant ssh
You will be dropped in a shell. User is vagrant and there is a password-less sudo configured for this user.
Hack *whack* hack!
After changing, editing, … a manifest, you can use the following command to re-run puppet without rebooting the machine:
[user@hostname ~/example]$ vagrant provision
Done!
After you finished doing stuff, you can bring the machine down with:
[user@hostname ~/example]$ vagrant destroy
Keep in mind that all changes you made to the vm will be lost after this as vagrant will make a fresh copy of the base box when running vagrant up
.
I found this when searching for help with Puppet. Your article doesn’t cover any puppet config really or anything to do with provisioning the VM.
Bummer.
You are right. I would like to add more information on that part but I’m just very short on time.
Great article. I just started using vagrant for “safe” puppet development.
Vagrant’s documentation is good.
Puppet’s documentation is good.
But, they should both link to your article. It’s a great way to start developing using both tools – without breaking a running puppetmaster.