Book Image

Infrastructure as Code (IAC) Cookbook

By : Stephane Jourdan, Pierre Pomès
Book Image

Infrastructure as Code (IAC) Cookbook

By: Stephane Jourdan, Pierre Pomès

Overview of this book

Para 1: Infrastructure as code is transforming the way we solve infrastructural challenges. This book will show you how to make managing servers in the cloud faster, easier and more effective than ever before. With over 90 practical recipes for success, make the very most out of IAC.
Table of Contents (18 chapters)
Infrastructure as Code (IAC) Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Index

Customizing a Vagrant VM


Vagrant supports many configuration options through the Vagrantfile. Here are the most useful ones for daily use.

Getting ready

To step through this recipe, you will need the following:

  • A working Vagrant installation (with a hypervisor)

  • An Internet connection

  • The Vagrantfile from the previous recipe using a bento/centos72 box

How to do it…

Here are some possible customizations for your Vagrant Virtual Machine.

Set the hostname

If you want to specify the VM name right from Vagrant, just add the following:

config.vm.hostname = "vagrant-lab-1"

This will also add an entry with the hostname to the /etc/host file.

Disable new box version check at startup

You may be using a slow internet connection, or you know you do want to use your current installed box, or maybe you're in a hurry and just want to get the job done; you can just remove the option to check for a new version of the box at startup by adding the following:

config.vm.box_check_update = false

Use a specific box version

If you know you want to use a specific version of the box (maybe for debugging purposes or compliance) and not the latest, you can simply declare it as follows:

config.vm.box_version = "2.2.9"

Display an informational message to the user

A useful feature is to display some basic but relevant information to the user launching the Vagrant box, such as usage or connection information. Don't forget to escape the special characters. As it's Ruby, you can access all available variables, so the message can be even more dynamic and useful to the user:

config.vm.post_up_message = "Use \"vagrant ssh\" to log into the box. This VM uses #{vm_cpus} CPUs and #{vm_memory}MB of RAM."

Specify a minimum Vagrant version

Vagrant is updated quite often, and new features are added regularly. A good practice, if you use a feature that is known to work only after a specific version, is to declare it in the Vagrantfile, so people with an older version know they have to update:

Vagrant.require_version ">= 1.8.0"