I have a need to create both some Ubuntu and CentOS Vagrant boxes for a project I am working on.
However in the past month HashiCorp have updated Atlas so that you can now build Packer 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.
Installing Packer & Vagrant
As I am 100% Mac based these instructions only cover installing Packer & Vagrant using Homebrew.
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;
First of all, ensure Homebrew is up-to-date;
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
⚡ 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 page. (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;
For this part of the blog post you can use my templates, you can grab them from GitHub using;
git clone <a href="https://github.com/russmckendrick/vagrant.git%5B/code%5D" target="_blank" data-href="https://github.com/russmckendrick/vagrant.git[/code]">https://github.com/russmckendrick/vagrant.git</a>
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 file 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 interface; The CentOS 7.1 build takes around 45 minutes to complete.
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.
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.
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 issue.