Friday, February 16, 2018

Up and running with Vagrant on Fedora 27

Vagrant, Ansible, Fedora and You

Having shied away from using Vagrant in the past I recently was forced to use it. I really enjoyed the workflow that it enabled; much better than manually restoring snapshots. One of the things that turned me off initially to using Vagrant was the requirement to use VirtualBox in earlier editions. This requirement has been removed in recent versions and you can now pick from many different providers.

The Install

The install is simple dnf install vagrant and after a minute or two you will have a fully working vagrant install using the libvirt provider.

Your First Vagrant Box

Make a new directory and setup your first Vagrantfile. To setup your first Vagrantfile lets run vagrant init centos/7. This will setup and new CentOS 7 box. Once that is done you will have a new Vagrantfile in the directory. You can choose from many different Vagrant boxes, each with a different OS or installed software. Run vagrant up and watch the output. After everything is up and working you can test it by logging into the machine with vagrant ssh.

Next Steps

Vagrant can be configured to automatically provision a host once it has come online. This feature is what changed my mind about Vagrant. So much faster and easier to test Ansible playbooks using this workflow. To enable the machine to be provisioned after boot edit your Vagrantfile and add: 

config.vm.provision "ansible_local" do |ansible|
  ansible.playbook = "playbook.yml"

in the config section of your file. This tells vagrant to run the playbook.yml using Ansible after the machine boots. You can also re-provision the machine by running vagrant up --provision. This will apply any changes you may have made to the playbook.yml after the machine is already running.