Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Infrastructure as Code Cookbook

You're reading from   Infrastructure as Code Cookbook Automate complex infrastructures

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher Packt
ISBN-13 9781786464910
Length 440 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Pierre Pomès Pierre Pomès
Author Profile Icon Pierre Pomès
Pierre Pomès
Stephane Jourdan Stephane Jourdan
Author Profile Icon Stephane Jourdan
Stephane Jourdan
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Vagrant Development Environments FREE CHAPTER 2. Provisioning IaaS with Terraform 3. Going Further with Terraform 4. Automating Complete Infrastructures with Terraform 5. Provisioning the Last Mile with Cloud-Init 6. Fundamentals of Managing Servers with Chef and Puppet 7. Testing and Writing Better Infrastructure Code with Chef and Puppet 8. Maintaining Systems Using Chef and Puppet 9. Working with Docker 10. Maintaining Docker Containers Index

Using a disposable Ubuntu Xenial (16.04) in seconds

We want to access and use an Ubuntu Xenial system (16.04 LTS) as quickly as possible.

To do that, Vagrant uses a file named Vagrantfile to describe the Vagrant infrastructure. This file is in fact pure Ruby that Vagrant reads to manage your environment. Everything related to Vagrant is done inside a block such as the following:

Vagrant.configure("2") do |config|
  # all your Vagrant configuration here
end

Getting ready

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

  • A working Vagrant installation
  • A working VirtualBox installation
  • An Internet connection

How to do it…

  1. Create a folder for the project:
    $ mkdir vagrant_ubuntu_xenial_1 && cd $_
  2. Using your favorite editor, create this very minimal Vagrantfile to launch an ubuntu/xenial64 box:
    Vagrant.configure("2") do |config|
      config.vm.box = "ubuntu/xenial64"
    end
  3. Now you can execute Vagrant, by explicitly using the Virtualbox hypervisor:
    $ vagrant up --provider=virtualbox
  4. Within seconds, you'll have a running Ubuntu 16.04 Vagrant box on your host and you can do whatever you want with it. For example, start by logging into it via Secure Shell (SSH) by issuing the following vagrant command and use the system normally:
    $ vagrant ssh
    Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-34-generic x86_64)
    […]
    ubuntu@ubuntu-xenial:~$ hostname
    ubuntu-xenial
    ubuntu@ubuntu-xenial:~$ free -m
    ubuntu@ubuntu-xenial:~$ cat /proc/cpuinfo
    
  5. When you're done with your Vagrant VM, you can simply destroy it:
    $ vagrant destroy
    ==> default: Forcing shutdown of VM...
    ==> default: Destroying VM and associated drives...
    

    Alternatively, we can just stop the Vagrant VM with the goal of restarting it later in its current state using vagrant halt:

    $ vagrant halt

How it works…

When you started Vagrant, it read the Vagrantfile, asking for a specific box to run (Ubuntu Xenial). If you previously added it, it will launch it right away through the default hypervisor (in this case, VirtualBox), or if it's a new box, download it for you automatically. It created the required virtual network interfaces, then the Ubuntu VM got a private IP address. Vagrant took care of configuring SSH by exposing an available port and inserting a default key, so you can log into it via SSH without problems.

You have been reading a chapter from
Infrastructure as Code Cookbook
Published in: Feb 2017
Publisher: Packt
ISBN-13: 9781786464910
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image