2015-10-29 90 views
3

我知道Ansible在Windows上运行时遇到问题。这就是为什么,我想避免将它用于我的主机。我想配置一个在VirtualBox中运行的本地linux虚拟机。配置Vagrant Linux VM与另一个运行Ansible的Vagrant Linux VM

我想知道是否有人可以告诉我,如果可能的话,使用vagrant在同一个盒子上调出两个独立的虚拟机。然后在其中一台虚拟机上安装Ansible,然后使用SSH登录到该虚拟机。从那里,使用带有Ansible的Linux VM作为主机,配置另一台通过Windows主机创建的Linux VM。所以,这不是虚拟机内部的虚拟机。这只是两个使用vagrant在windows上运行的虚拟机,然后通过SSH连接到其中一个虚拟机以使用Ansible来配置其他虚拟机。

步骤:

  1. 流浪VM 1和安装Ansible
  2. Vangrant VM 2
  3. SSH到VM 1
  4. 使用Ansible到规定VM 2使用VM 1.

可以这样做吗?对不起,如果这听起来令人困惑。

+0

的可能的复制[?能否提供流浪汉虚拟机使用别的流浪VM的Ansible安装(http://stackoverflow.com/questions/33393748/can-vagrant-provision -vm-using-an-ansible-installation-in-another-vagrant-vm) – ydaetskcoR

回答

4

Vagrant 1.8.0现在有new Ansible local provisioner,您可以在您的方案中使用它。

特别是,看文档的“提示和技巧”部分,有一个确切的解决方案(这对我有效)。

下面是我Vagrantfile对于这种情况,这也解决了潜在的问题与SSH权限和“执行”清单文件(如果你使用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 
3

为了配置一个盒子,您不需要使用另一个盒子,在这个窗口场景中,您可以简单地编写您的剧本,将它分享给您的客人,并使用shell供应与ansible-playbook匹配。

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 

$script = <<SCRIPT 
sudo apt-get install -y software-properties-common 
sudo apt-add-repository -y ppa:ansible/ansible 
sudo apt-get update 
sudo apt-get install -y ansible 
ansible-playbook /home/vagrant/provisioning/playbook.yml 
SCRIPT 

config.vm.synced_folder "./provisioning", "/home/vagrant/provisioning" 

config.vm.provision "shell", inline: $script 

end 

第一行会得到你的盒子ansible然后它会针对您已经共享给你的盒子的剧本和运行剧本。

这是一个例子,我曾经用这种方法来配置我的工作游民箱,希望这个想法能帮助你。

+0

但是,这不是仍然使用Windows作为主机?我想避免在主机上使用windows,因为设置cygwin是一件痛苦的事情,并且希望按照预期使用它。 – CodyK

+0

这是作为主机在窗户上,但没有安装在主机上,它只在你的流浪箱上。流浪者窗口将使用外壳提供者仅在框上运行这些命令。你不需要在主机上获取cygwin。 – Alberick0

+0

那么,基本上它是运行本地剧本,通过运行本地主机? – CodyK

相关问题