Multiple Vagrant boxes via Ansible?

Hello all, I am very new to Vagrant and its concepts, so please forgive me if this is a stupid question.

I want to automate the creation of a couple of Vagrant boxes via Ansible, but I am bot sure if this can be achieved: i want an arbitrary numero of boxes attached to the public network with a static IP that I want to pass at runtime.
Any help is very welcome, thanks.

1 thought on “Multiple Vagrant boxes via Ansible?”

  1. Packer (also by HashiCorp) is the tool you want to use to actually create boxes. You can use an Ansible playbook to ‘provision’ the box before packaging.

    Not sure if that’s what you’re looking for though if the goal is to simply assign a static ip when the VM boots. In that case you could use Ansible, again as a provisioner, then take the IP from your inventory or pass it in as extra_vars.

    A Vagrantfile is ultimately a ruby script, so you can use environment variables, parse input, and all that other good stuff you’d get from a normal ruby script. Use this in combination with the network config available from Vagrant and you wouldn’t need Ansible at all as your ‘static’ IP would just be a variable that gets defined by the env / arguments.

    Not sure what the use case is here, but if it’s about making VMs easy to access (aka memorable IPs), check out the vagrant-hostmanager plugin. I do something similar to the second approach to give VMs that use the same base box a different hostname that’s easier to remember than an IP. It also allows me to let DHCP manage the address assignment so I don’t have conflicts should I accidentally reuse the same static IP across boxes / use an IP already taken by some other service.

    Reply

Leave a Comment