To change setup content by project in multiple Vagrant files

Asked 2 years ago, Updated 2 years ago, 122 views

Up until now, I have used only one Vagrant, but now I need another set-up with the same operating system.
If you create a new vagrantfile in a different directory and do a vagrantup, the contents of the second device will somehow be adapted to both the first and second devices.

[Host Configuration]
localnginx.dev 192.168.33.10
localapache.dev 192.168.33.11

1First vagrantfile <

Vagrant.configure(2) do|config|
  config.ssh.insert_key=false
  
  config.vm.define: "localnginx.dev" do | web_config |
    web_config.vm.box="bento/centos-6.8"
    web_config.vm.network "private_network", ip: "192.168.33.10"
    web_config.vm.synced_folder "../home/sample1", "/home/sample1/htdocs", :nfs=>{:mount_options=>["dmode=777", "fmode=644" ]}

    web_config.vm.provision "ansable" do | answer |
      available.playbook="site.yml"
      available.inventory_path="hosts/development"
      available.limit="all"
    end

    web_config.vm.provider "virtualbox" do | vb|
      vb.name="localnginx.dev"
      vb.memory="2048"
      vb.customize ["modifyvm",:id, "--natdnshostresolver1", "on" ]
    end
  end
end

台Second vagrantfile <

Vagrant.configure(2) do|config|
  config.ssh.insert_key=false
  
  config.vm.define: "localapache.dev" do | web_config |
    web_config.vm.box="bento/centos-6.8"
    web_config.vm.network "private_network", ip: "192.168.33.11"
    web_config.vm.synced_folder "../home/sample2", "/home/sample2/htdocs", :nfs=>{:mount_options=>["dmode=777", "fmode=644" ]}

    web_config.vm.provision "ansable" do | answer |
      available.playbook="site.yml"
      available.inventory_path="hosts/development"
      available.limit="all"
    end

    web_config.vm.provider "virtualbox" do | vb|
      vb.name="localapache.dev"
      vb.memory="2048"
      vb.customize ["modifyvm",:id, "--natdnshostresolver1", "on" ]
    end
  end
end

[Prerequisite]

  • The contents of the Vagrantfile, the directory you want to mount, and the available-playbook are different.
  • I want to create a completely different setup environment for each project, even with the same OS (CentOS 6.8).

[Problems]

  • The second sync_folder is also adapted to the first
  • The tasks registered in the second available-playbook will also be adapted to the first one

I've been looking for this cause for a while, but it's hard to find it, so
It would be very helpful if you could give me some advice.Thank you for your cooperation.

vagrant

2022-09-30 19:33

1 Answers

The reason was that the previous vagrant configuration was copied by directory, and the .vagrant directory was also copied.

This post was posted as an individual response on the community wiki based on what @stlab wrote in the questionnaire.


2022-09-30 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.