将Vagrant Linux VM配给另一个运行Ansible的Vagrant Linux VM [英] Provision Vagrant Linux VM with another Vagrant Linux VM running Ansible

查看:96
本文介绍了将Vagrant Linux VM配给另一个运行Ansible的Vagrant Linux VM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Ansible在Windows上运行时遇到问题.这就是为什么我要避免将其用于主机.我想设置在VirtualBox中运行的本地linux vm.

I know Ansible has issues running on windows. Which is why, I want to avoid using it for my host. I want to provision a local linux vm running in VirtualBox.

我想知道是否有人可以告诉我,是否可以使用流浪汉在同一台机器上启动两个独立的VM.然后在其中一台VM上安装Ansible,然后使用SSH登录到该VM.从那里,使用具有Ansible的Linux VM作为主机,以配置通过Windows主机创建的另一个Linux VM.因此,这不是VM内的VM.只是两个使用流浪汉在Windows上运行的VM,然后通过SSH到其中一个VM来使用Ansible来配置另一个VM.

I was wondering if anyone can tell me if it is possible, to use vagrant to bring up two independent VMs on the same box. Then install Ansible on one of those VMs, then using SSH log into that VM. From there, use the Linux VM with Ansible as the host, to provision another Linux VM, that was created via the windows host machine. So, this is not a VM inside a VM. It is just two VMs running on windows using vagrant, then SSH to one of those VMs to use Ansible to provision the other VM.

步骤:

  1. Vagrant VM 1并安装Ansible
  2. Vangant VM 2
  3. SSH到VM 1
  4. 使用Ansible通过VM 1设置VM 2.

可以做到吗?抱歉,这听起来令人困惑.

Can that be done? Sorry if that sounded confusing.

推荐答案

现在有一个 流浪者1.8中的新Ansible本地供应商 .0 ,您可以在方案中使用它.

There is now a new Ansible local provisioner in Vagrant 1.8.0, which you can use in your scenario.

尤其是,查看文档的技巧和窍门"部分,有一个确切的解决方案(对我有用).

Especially, look at "Tips and Tricks" section of the documentation, there is an exact solution (which worked for me).

以下是我在这种情况下的Vagrantfile(与文档中的Vagrantfile略有不同),它还解决了ssh权限和可执行"清单文件(如果使用Cygwin)的潜在问题:

Below is my Vagrantfile for this scenario (slightly different from the one in the documentation), which also solves potential problems with the ssh permissions and "executable" inventory file (if you're using Cygwin):

Vagrant.configure(2) do |config|
  config.vm.synced_folder "./", "/vagrant", 
     owner: "vagrant",
     mount_options: ["dmode=775,fmode=600"]

  config.vm.define "vm2" do |machine|
    machine.vm.box = "box-cutter/ubuntu1404-desktop"
    machine.vm.network "private_network", ip: "172.17.177.21"
  end

  config.vm.define 'vm1' do |machine|
    machine.vm.box = "ubuntu/trusty64"
    machine.vm.network "private_network", ip: "172.17.177.11"    

    machine.vm.provision :ansible_local do |ansible|
      ansible.provisioning_path = "/vagrant"
      ansible.playbook = "provisioning/playbook.yml"      
      ansible.limit = "vm2"
      ansible.inventory_path = "inventory"
      ansible.verbose = "vvv"
      ansible.install = true    
    end
  end
end

和库存文件:

vm1 ansible_connection=local
vm2 ansible_ssh_host=172.17.177.21 ansible_ssh_private_key_file=/vagrant/.vagrant/machines/vm2/virtualbox/private_key

这篇关于将Vagrant Linux VM配给另一个运行Ansible的Vagrant Linux VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆