I have a need to create both some Ubuntu and CentOS Vagrant boxes for a project I am working on.

Normally I would have created them on my local machine, uploaded the artifacts to an Amazon S3 bucket and then published them using Atlasexternal link (formally Vagrant Cloudexternal link ).

However in the past month HashiCorpexternal link have updated Atlas so that you can now build Packerexternal link templates directly within Atlas and publish the artifacts as Vagrant Boxes, all free of charge. This is great for me as it means that I will not incur the hosting and distribution costs.

Getting started

If you haven’t already sign up for an Atlas accountexternal link . I would recommend that you immediately enable two factor authenticationexternal link just incase.

Installing Packer & Vagrant

As I am 100% Mac based these instructions only cover installing Packer & Vagrant using Homebrewexternal link .

For the Atlas interaction you need to make sure you are using the latest versions of both pieces of software, at the time of writing these are;

  • Packer 0.8.2
  • Vagrant 1.7.4

First of all, ensure Homebrew is up-to-date;

brew update

Once updated you can install the software by using;

[code gutter=”false”]brew install packer brew install cask brew cask install vagrant[/code]

Finally, check the versions you have installed;

⚡ packer version
Packer v0.8.2

and;

⚡ vagrant version
Installed Version: 1.7.4
Latest Version: 1.7.4

You’re running an up-to-date version of Vagrant!

Getting a token

Now you have signed up and have the latest versions of Packer & Vagrant installed you will need to generate a token, this will allow Packer to interact with Atlas.

You can get a token from your settings pageexternal link .

tokens-for-russmckendrick-atlas-by-hashicorp

(yes, the token above has been revoked so you can’t use it)

As the message on the page says, make a copy of your token as you will not be able to see it again. Once you have your access token you will need to set it as a environment variable;

export ATLAS_TOKEN=axYdYYAte8MGqw.atlasv1.n3pj1oC9qQq4DRbPxykJy3pSHlDoFzfsBkGTrEqq3WWZarX8tuaHjr1gkdenRAazdLo

Packer

For this part of the blog post you can use my templatesexternal link , you can grab them from GitHub using;

git clone https://github.com/russmckendrick/vagrant.git

Lets use the CentOS 7.1 template, open centos7.json in your text editor of choice and update the variables at the bottom of the fileexternal link replacing the atlas_username, atlas_name and artifactversion as needed.

Next up should use packer validate to check there are not any errors with the template file;

⚡ packer validate centos71.json
Template validated successfully.

Once you have validated the template you will need to push the template to Atlas using packer push;

⚡ packer push -m “Initial Push” centos71.json
Push successful to ‘russmckendrick/centos71’

Once the template has been pushed you should see the build in the web interfaceexternal link ;

build-configuration-russmckendrick-centos71-atlas-by-hashicorp

The CentOS 7.1 build takes around 45 minutes to complete.

Vagrant

Once the build has completed the artifact will be automatically uploaded to Atlas using the variables you defined earlier in the post. You can view your Vagrant Boxes in the web interface.external link

Once completed you will be able to use the boxes with the commands which accompany the release e.g.

vagrant init russmckendrick/centos71; vagrant up — provider virtualbox

or for VMWare;

vagrant init russmckendrick/centos71; vagrant up — provider vmware_fusion

Remember to wait until the build has completed the version is labelled as released before trying to use the box.

Trouble Shooting

One the problems I came across when converting my existing Packer templates to using the Atlas Post-Processor was that I didn’t next the arrays, this resulted in problems with the metadata for the box being correctly embedded which caused errors when trying to launch the box.

The problem is detailed this GitHub issueexternal link .