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

假装没事ソ 提交于 2019-12-12 05:39:31

问题


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?


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/33393748/can-vagrant-provision-a-vm-using-an-ansible-installation-in-another-vagrant-vm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!