Build a Provisioning Dev Environment with Vagrant

Building Your Infrastructure Development Environment (IDE) – Then Tearing it Down!

You need an Infrastructure Development Environment (IDE) as you are modelling your infrastructure as code. Software developers use sophisticated IDEs. That doesn’t exist yet so this resource helps you create your own powerful IDE (Infrastructure Development Environment).

Your IDE is Better – Because you Destroy It Every Day

Software developers should destroy their IDE before they leave the office – and in the morning – they should press a button to rebuild up their destroyed IDE. This sounds extreme but it guarantees a completely automated development environment.

If this practice is maintained – a newbie developer would sit down on their first day and create their entire IDE and sandbox with just one click.

As an infrastructure developer you are going to do it better than the software developers. You are going to create your IDE in the morning and destroy it in the evening. You will even create your Continuous Integration environment in the morning and destroy it in the evening.

The Cloud – And Everything In It

That’s right – you are going to create your own cloud – and everything in it. And just before you head home – you are going to set that cloud on fire.

Immutable – Not Idempotent

Aim to have immutable infrastructure. Not idempotent. Never make an incremental change to a server or container or network component. Don’t release code today to a server that was built yesterday. Just rebuild the server and deploy the code within an infrastructural “synchronized” block.

Use Vagrant to Create an Ansible (Ubuntu) Virtual Machine on a Windows Host

We will use Vagrant to create the environment (IDE) which will be powered primarily by Ansible. Ansible will subsequently create your infrastructure – primarily using Docker containers and Cloud EC2 servers running Linux or Windows. We will also use AWS CLI (command line interface) and other best of breed local and cloud based tools.

As a DevOps engineer you need to control multiple servers in the cloud, on local virtual machines and/or on a fleet of bare metal servers.

Vagrant builds a virtual machine and installs Ansible. It also installs some productivity tools for the captain DevOps engineer who steps onto the bridge by logging in

Pets vs Cattle? – One Pet – Many Cows

This is the first step in an automated provisioning process that will create every single server, container and network configuration within your company.

Your only pet is your Windows 7, 8 or 10 client. Everything else is cattle. Use the below as a starting point to your brand new automatically provisioned infrastructure.

Use Vagrant to Create an Ansible (Ubuntu) Virtual Machine on a Windows Host

Purpose – Why get Vagrant to build an Ansible Control Desk?

When a DevOps engineer arrives in the morning, they run this script and log into their new Ansible command and control console.

They then use the Ansible orchestration environment to model the infrastructure. Throughout the day Ansible uses the scripted model to build, validate and destroy infrastructure elements.

Other productivity tools like a VCS interface and an editor are built into the environment.

Using Vagrant on Windows to Provision an Ubuntu Server

Precondition 1 : Vagrant is installed on your Windows server.

Precondition 2 : Ensure that Virtualization is enabled in the Bios. If it isn’t – you will get an error message that says something like Stderr: VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes.

  1. Crreate folder machines off your home directory
  2. Download
  3. Put Vagrantfile in the machines folder (see below for Windows download command).
  4. Run vagrant init ubuntu/xenial64 to create an Ubuntu 16.04 virtual machine
  5. Use vagrant up to build the Ubuntu server

Stderr: VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes

wget on windows – Download Vagrantfile with Powershell

You can mimic the Linux wget to get Vagrantfile. To do this press Windows button and r to pull up the run dialog. Then type powershell. Navigate to your machines folder and run this command.

wget -o Vagrantfile

Be Careful – Folder Location in Windows 10

Vagrant is really helpful. As such and deploy it within VirtualBox to

  • Vagrant may install VirtualBox for you if necessary.
  • It downloads the Ubuntu Xenial ISO file if it is not in Vagrant’s cache.
  • Creates an Ubuntu 64 virtual machine within VirtualBox.

Vagrant – Seeing is Believing

Visit the VirtualBox UI to check that Vagrant has indeed booted up a virtual server. You don’t need to as VirtualBox runs in headless mode in the background. However it can be handy to check whether your virtual machine is installed, running or absent.

Be Careful – Folder Location in Windows 10

In Windows 10 you must create the machines folder within your home C:\Users\<your-name> folder tree. If you don’t you risk a Vagrant error like this one (it can’t read external folders).

There was an error loading a Vagrantfile. The file being loaded and the error message are shown below. This is usually caused by a syntax error.

Using Vagrant to Destroy the Ubuntu Virtual Machine

It is important to always destroy the machine immediately. Never go home with a sandbox up and running. You destroy it and tomorrow you build another one.

  1. Type vagrant halt to stop the virtual machine
  2. Type vagrant destroy to destroy the virtual machine
  3. Type vagrant help for a list of commands

Vagrant and Ansible – What Just Happened?

When Vagrant builds a network visible Ansible command and control host it starts by commissioning a virtual machine and then runs the script. This script

  1. commissions a virtual machine
  2. installs an editor and a vcs client
  3. checks out the infrastructure assets
  4. installs Ansible
  5. accessorizes the ssh keys of known hosts
  6. prints out the new host’s SSH address

Your IDE – Infrastructure Development Environment

This script effectively builds your IDE environment where I stands for Infrastructure. The script downloads (from version control in Git or Subversion) your entire infrastructure-centric code base. This is your new Ansible command and control platform.

Don’t Forget Continuous Integration for Infrastructure

If and when the DevOps engineer performs a check-in, the infrastructure continuous integration environment is set in train. It checks out the new infrastructure scripts, builds an instance of the design model, tests and then destroys it.

What should be done next?

After the script runs – you (the DevOps engineer) are invited to step onto the bridge by logging into the Ansible command and control dashboard.

Leave a Reply

Your email address will not be published. Required fields are marked *