使用另一个运行 Ansible 的 Vagrant Linux VM 配置 Vagrant Linux VM [英] Provision Vagrant Linux VM with another Vagrant Linux VM running Ansible

查看:31
本文介绍了使用另一个运行 Ansible 的 Vagrant Linux VM 配置 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.

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

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. Vangrant VM 2
  3. 通过 SSH 连接到 VM 1
  4. 使用 Ansible 配置使用 VM 1 的 VM 2.

能做到吗?对不起,如果这听起来令人困惑.

Can that be done? Sorry if that sounded confusing.

推荐答案

现在有一个 Vagrant 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(与文档中的略有不同),它还解决了 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

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

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