Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为Vagrant Linux VM提供另一个运行Ansible的Vagrant Linux VM_Linux_Windows_Vagrant_Ansible - Fatal编程技术网

为Vagrant Linux VM提供另一个运行Ansible的Vagrant Linux VM

为Vagrant Linux VM提供另一个运行Ansible的Vagrant Linux VM,linux,windows,vagrant,ansible,Linux,Windows,Vagrant,Ansible,我知道Ansible在windows上运行时出现问题。这就是为什么我不想把它用在我的主机上。我想配置一个在VirtualBox中运行的本地linux虚拟机 我想知道是否有人可以告诉我,是否有可能,使用vagrant在同一个盒子上显示两个独立的虚拟机。然后在其中一个虚拟机上安装Ansible,然后使用SSH登录到该虚拟机。然后,使用带有Ansible的Linux虚拟机作为主机,以提供另一个通过windows主机创建的Linux虚拟机。所以,这不是虚拟机中的虚拟机。它只是在windows上使用vag

我知道Ansible在windows上运行时出现问题。这就是为什么我不想把它用在我的主机上。我想配置一个在VirtualBox中运行的本地linux虚拟机

我想知道是否有人可以告诉我,是否有可能,使用vagrant在同一个盒子上显示两个独立的虚拟机。然后在其中一个虚拟机上安装Ansible,然后使用SSH登录到该虚拟机。然后,使用带有Ansible的Linux虚拟机作为主机,以提供另一个通过windows主机创建的Linux虚拟机。所以,这不是虚拟机中的虚拟机。它只是在windows上使用vagrant运行的两个虚拟机,然后通过SSH连接到其中一个虚拟机,使用Ansible配置另一个虚拟机

步骤:

  • Vagrant VM 1并安装Ansible
  • Vangrant VM 2
  • SSH到VM 1
  • 使用Ansible可以使用VM 1配置VM 2

  • 那能做到吗?如果这听起来让人困惑,我很抱歉

    为了配置一个盒子,您不需要使用另一个盒子,在这个windows场景中,您只需编写您的剧本,将其分享给您的客户,然后使用
    shell
    配置
    ansible剧本
    点击即可

    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
    
    Vagrant.configure(Vagrant文件API版本)do | config|
    $script=现在有一个in,您可以在场景中使用它

    特别是,看看文档中的“提示和技巧”部分,有一个精确的解决方案(对我来说很有用)

    下面是这个场景的Vagrant文件(与文档中的略有不同),它还解决了ssh权限和“可执行”清单文件(如果您使用的是Cygwin)的潜在问题:

    和库存文件:

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

    可能重复,但是否仍使用Windows作为主机?我想避免使用windows ansible拥有主机,因为安装cygwin很麻烦,我想按预期使用它。这是在windows上作为主机安装的,但ansible没有安装在主机上,它只安装在您的“流浪者”框上。vagrant windows将使用shell provisioner仅在box上运行这些命令。你不需要让cygwin在主机上运行这个。所以,基本上它是运行一个本地剧本,通过对本地主机运行ansible?没错。它安装ansible并针对本地主机运行playbook。所有这些都是使用shell provisiongawesome完成的,这是完美的。
    vm1 ansible_connection=local
    vm2 ansible_ssh_host=172.17.177.21 ansible_ssh_private_key_file=/vagrant/.vagrant/machines/vm2/virtualbox/private_key