3

I understand that Vagrant is a tool to create and manage virtual machines; and that Ansible is a tool to configure one's machines (virtual or otherwise).

However, Ansible's AWS modules are capable of creating and managing AWS resources—combined with its dynamic AWS inventory, this would yield a thoroughly portable management tool. Whilst the vagrant-aws plugin can also create and manage AWS resources, am I right in thinking that it cannot so easily manage the same resources quite so portably (i.e. a new management host could download the Vagrantfile but would not be able to manage existing AWS resources)?

If so, what advantages are there (if any) to using Vagrant for managing AWS resources (if one is already using Ansible for provisioning), versus using Ansible for both resource management and provisioning?

1 Answer 1

4

You're mostly correct I think - if you ONLY want to manage EC2 instances - although vagrant can easily use Ansible's dynamic inventory system: http://docs.vagrantup.com/v2/provisioning/ansible.html:

Static Inventory

The second option is for situations where you'd like to have more control over the inventory management. With the ansible.inventory_path option, you can reference a specific inventory resource (e.g. a static inventory file, a dynamic inventory script or even multiple inventories stored in the same directory). Vagrant will then use this inventory information instead of generating it.

This option should probably be called 'existing inventory' or 'external inventory' or something - it just means 'use an inventory that Vagrant didn't generate'.

The real advantage of Vagrant is being able to use the same/similar Vagrantfiles for multiple environments - with the exact same Ansible scripts. So Virtualbox VM's for dev and EC2 for stage/prod with the same Ansible provisioning scripts - and either the same vagrantfile, or two very similar ones.

At that point, you could switch to Docker with a simple change to the provider in the Vagrantfile - or even using --provider on the command line.

The way Vagrant implements back-end providers makes switching pretty simple.

Vagrant also provides a simple built in command line interface for managing your boxes - seeing status, stopping, starting, rebooting, etc:

vagrant status
vagrant up <machine>
vagrant destroy -f <machine>

which works the same, regardless of the backend provider - Virtualbox, EC2, etc... as well as a load of plugins for other useful things: https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins

But, it's not perfect. The vagrant-aws plugin doesn't get a lot of love and if you have complex AWS needs, you might be better off rolling something yourself, either with scripts + Ansible, or Ansible on it's own.

1
  • Ah; that clears up two misunderstandings: (1) Vagrant's "static inventory" option can actually utilise a dynamic Ansible inventory; and (2) any such "static inventory" is not just used by Ansible, but also by Vagrant. In this new light, I'm beginning to see some advantages (as you describe). Thank you!
    – eggyal
    Aug 4, 2015 at 17:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .