This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do.
Foreword
Youve probably heard the old saying Jack of All Trades, Master of None.
According to Wikipedia, its a very old saying, with the Jack of All Trades part dating back to the early 1600s. Originally, it was a compliment, praising someone for their diversity and handiness. Some wiseguy later added Master of None and changed it to the insult we know today.
Personally, that seems unfair. The world needs generalists: people who borrow from other languages, cross-pollinate between communities, reuse old tools for new purposes. True, theyre often not the deepest experts in these fields. Yet they can make valuable contributions because they have so many references to draw from. Perhaps thats why theres a modern variation of the saying: Jack of All Trades, Master of None, but often better than a Master of Any.
Likewise, this book might say Vagrant Cookbook on the cover but if you dig deeper, youll find its about an entire ecosystem of tools. To get the most out of Vagrant, you need to know about provisioners, plugins, virtualization platforms, shell commands and more. Luckily, you dont need to master any of them (though thats always nice), you just need to be effective: A Jack (or Jill) of All Trades.
If youre new to Vagrant, this book is going to teach you how to start and help you make decisions about what tools to use. If already have Vagrant experience, the sections on alternative provisioners or multiple VMs are sure to have something new for you.
Introducing Vagrant is often a first step towards DevOps. If thats the case for you, keep in mind the two virtues of communication and automation. Communicating openly will expose you to new viewpoints, new concerns and new references. Automation will let your team wield powerful tools while distributing the time investment. Together, these two things will help you grow team members who are Jacks of All Trades, Master of Some.
This book is full of great tips and tricks for using Vagrant but theres one lesson in particular I hope you take from it. In an industry known for high stress and crazy deadlines, Erikas enthusiasm is inspiring. Whether shes automating image processing or drawing cartoon elephants, her approach can only be described as joyful.
That she channeled this energy and talent into an (excellent) book about virtual machine management should remind us how amazing computers really are. Her example encourages us to always set the bar just a little bit higher: not just in the work we do, but also in the fun we have.
Thanks for picking up the Vagrant Cookbook. Youre in the right place.
Ross Tuck
Amsterdam, March 2014
Preface
I remember very clearly the first time I heard about Vagrant. It was early 2013, on my second visit to the AmsterdamPHP meetups. The talk was from my dear friend Michelle Sanver (a.k.a. Geekie), about Open Source. She was showing how easy it is to get involved and contribute to OSS projects, by simple cloning the project repository and running the mysterious command vagrant up
.
I started using Vagrant the next day.
A few months later, and not before facing a considerable resistance from my coworkers and the lead developer (they were using remote servers for testing - FTP upload for every single change), I was able to introduce Vagrant in the company I was working for. Although that project was quite complex and creating a Puppet provision for it was slightly painful, it was a great opportunity to learn more about Vagrant and get used to the tricks and the automate all the things mindset.
After leaving the company and coming back to my independent projects, I started to submit some talks for PHP conferences, and naturally Vagrant was on top of my cool-subjects list. By that time, I was presented to LeanPub and found out the amazing platform they built for self-publishing - I must say that I personally love any service that promotes independent work. Its also no news that writing is a passion for me since I was little. So, connecting the dots, it was an obvious decision: I should write about my experiences with Vagrant.
This book is based on many experiments and lots of research, from a very curious and enthusiastic Vagrant user. I tried to put together everything you need to have a pleasant experience with Vagrant, in a truly practical way.
Acknowledgments
A special thanks to all the people who helped me directly or indirectly, including Mitchell Hashimoto, Vagrants creator, not only for sharing such a great project with the developers community, but also for personally helping me to spread the word about my Vagrant usage research.
Thanks LeanPub for providing a complete self-publishing platform for independent writers, with so many nice features.
A big thanks must go to my friend Ross Tuck for writing an inspired and truthful foreword for this book.
I also would like to thank the PHP community, and specially the AmsterdamPHP user group, for the warm welcome I received since I moved from my hometown in Brazil to this amazing city, for the awesome friends I made and all support and encouragement they gave me.
And finally, I want to thank my husband, Hugo, for being incredibly supportive with my independent projects, for the faith he has in me and in my work. This book would hardly be possible without him.
Introduction
How many times did you hear the sentence but it works on my machine ? I bet you already said that too, because, well, it happens. We cant remember all the packages we already installed and all the configurations we set in our work machine, so it often takes some time to find out what went wrong when the project was shared to another co-worker, or worst, when deploying.
Also, if we need to deal with multiple projects, how to manage the dependencies and different software versions possibly needed?
If you are not familiar with Vagrant, this is the right moment to get acquainted to it. Vagrant provides a portable and reproducible development environment using virtual machines, all set up in the project repository - just clone, run vagrant up
and youre done. You will never be hostage of the works on my machine statement again; the environment is exactly the same for all developers, regardless of the operating system running behind Vagrant.
Vagrant for proprietary projects
Vagrant can make your workflow way easier when you are working on a team; having the exact same testing environment for all co-workers will avoid many problems and add much more consistency to the overall project development.
Vagrant for open source projects
Vagrant enables more developers to contribute to your open source project - just clone the repository and you are ready to go. Its not only about setting up the right environment, but also automating the process of installing a database, cloning repositories, adding data fixtures and even running tests.