Marco Ferrari
Marco Ferrari

Reputation: 5253

Can Vagrant provision a VM using an Ansible installation in another Vagrant VM?

I just started using Ansible and Vagrant to bootstrap a local development environment (let's call it dev-server-1) and the host is a Windows machine (win-host).

I have to provision dev-server-1 machine using Ansible, but win-host is running Windows so I was wondering if I could use another Vagrant VM (ansible-host, running a minimal box with Ansible installed) just for Ansible, but leaving dev-server-1 running on win-host. Is this feasible?

Upvotes: 0

Views: 478

Answers (2)

Jean Guzman
Jean Guzman

Reputation: 2212

I have proposed a solution in this question: Provision Vagrant Linux VM with another Vagrant Linux VM running Ansible

Which I think it can work for you as well it's basically to provision the vagrant box using shell to install ansible on your guest and to run ansible against your localhost(on your vagrant box).

Upvotes: 2

ydaetskcoR
ydaetskcoR

Reputation: 56937

You won't be able to use the built in Ansible provisioner in Vagrant as that relies on the host having both Ansible installed and also an OS that supports ControlPersist (which Windows doesn't).

You could however use Vagrant to spin up your bare VMs and then use a separate VM (possibly created by Vagrant) with Ansible installed to then configure these other VMs.

The only thing you would need for that is for there to be network connectivity between the VMs.

Unfortunately you will not be able to use the auto generated inventory that Vagrant creates on running an Ansible provisioner as it requires an Ansible provisioner to be run. As far as I know there is no way to get this inventory without running the Ansible provisioner.

Upvotes: 1

Related Questions