What is Vagrant?
Puppet Master with Vagrant, but what is Vagrant? Vagrant is an open-source software product by HashiCorp for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. It tries to simplify the software configuration management of virtualizations in order to increase development productivity.
Vagrant really comes into its own when you need something more than a Docker image. In simplistic terms, it provides you with a nice packaged “Vagrant” file to install a “Vagrant VM”. It’s great because it’s repeatable and you can ensure if you are using it as part of a lab or test suite that each Virtual Machine is identical.
Puppet Master with Vagrant
I’ve been using Vagrant with Oracle Databases and Ansible for years it’s quick and easy and saves me the hassle of going through the oracle install process each time I want a database, with Vagrant I can simply navigate to the location of my Vagrant File and type “vagrant up”.
In my work, I have had started to focus more on Puppet so I embarked on a quest to create a Puppet Master vagrant file at home so I can spin up my own puppet master within a virtual machine to help with my own learning. I found this great GitHub repository that had already done much of the work but it hadn’t been touched or updated for years so I forked the code (here) and started my own journey.
I have successfully upgraded the base OS to Ubuntu 20.04 (LTS) and upgraded to Puppet 7. I am still not all the way there yet having some issue with a dashboard module that I am trying to get my head around if anyone fancied helping with all the code on GitHub feel free to pull it down and have a look for yourself.
Using Vagrant
Install the vagrant application from the Vagrant site you also need to ensure you have Virtual Box or VMware installed. I use Virtual Box myself as it’s just what I am most familiar with but the steps involved are the same regardless.
Use Git to clone the vagrant files to your own machine;
git clone https://github.com/pazyp/vagrant-puppetmaster.git
This should be pretty fast, navigate to the downloaded code and start the vagrant host;
cd vagrant-puppetmaster
vagrant up
Running vagrant up will star the process of building the Virtual Machine and installing Puppet the whole process takes about 15min to be left with a usable Puppet Master.
Useful Vagrant Commands
A list of commands for reference that can help you out using Vagrant
Creating a VM
vagrant init — Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you’ll need to specify a base image in the Vagrantfile.
vagrant init <boxpath> — Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace its name with box path. For example, vagrant init ubuntu/trusty64.
Starting a VM
vagrant up — starts vagrant environment (also provisions only on the FIRST vagrant up)
vagrant resume — resume a suspended machine (vagrant up works just fine for this as well)
vagrant provision — forces reprovisioning of the vagrant machine
vagrant reload — restarts the Vagrant machine, loads new Vagrantfile configuration
vagrant reload --provision — restart the virtual machine and force provisioning
Getting into a VM
vagrant ssh — connects to the machine via SSH
vagrant ssh <boxname> — If you give your box a name in your Vagrantfile, you can ssh into it with box name. Works from any directory.
Stopping a VM
vagrant halt — stops the vagrant machine
vagrant suspend — suspends a virtual machine (remembers state)
Cleaning Up a VM
vagrant destroy — stops and deletes all traces of the vagrant machine
vagrant destroy -f — same as above, without confirmation
Boxes
vagrant box list — see a list of all installed boxes on your computer
vagrant box add <name> <url> — download a box image to your computer
vagrant box outdated — check for updates vagrant box update
vagrant boxes remove <name> — deletes a box from the machine
vagrant package — packages a running VirtualBox env in a reusable box
Saving Progress
–vagrant snapshot save [options] [vm-name] <name> — vm-name is often default. Allows us to save so that we can rollback at a later time
Tips
vagrant -v — get the vagrant version
vagrant status — outputs status of the vagrant machine
vagrant global-status — outputs status of all vagrant machines
vagrant global-status --prune — same as above, but prunes invalid entries
vagrant provision --debug — use the debug flag to increase the verbosity of the output
vagrant push — yes, vagrant can be configured to deploy code!
vagrant up --provision | tee provision.log — Runs vagrant up, forces provisioning and logs all output to a file
Conclusions
As I said at the start of the article Vagrant is great when you need something more traditional that a docker image and since its a Virtual Machine with a little work, time and patience you should be able to replicate any production environment to have a reusable testing host to increase your DevOps productivity.
Top comments (0)