Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share one Vagrant instance between different directories

Tags:

vagrant

I have a few directories with different Mercurial histories that I am working on in parallel. They all have the same Vagrantfile so it would be natural to use just one instance for all of them. But when I run "vagrant up" in a new directory, it starts from linking the existent VM, setting up the environment, and so on. How do I share the Vagrant instance between different directories?

UPDATE: my directory structure:

\
 Vagrantfile
 puppet
  *.pp
 support
  nginx.conf
  uwsgi.development.ini
 other_repo_related_files_and_dirs
like image 340
Anton Zhdanov Avatar asked Mar 21 '23 18:03

Anton Zhdanov


1 Answers

Well, if you want to share some directories with the same Vagrant's instance, you can configure the Vagrantfile.

This is an example with two VM (app and web), using the same box (ubuntu-12.04) and the same Vagrantfile. Each instance have two folders (one folder by VM).

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define 'app' do |app_config|
    app_config.vm.box = 'ubuntu-12.04'
    app_config.vm.host_name = 'app'
    app_config.vm.network "private_network", ip: "192.168.33.33"
    app_config.vm.synced_folder "app_config", "/app_config"    
  end
  config.vm.define 'web' do |web_config|
    web_config.vm.box = 'ubuntu-12.04'
    web_config.vm.host_name = 'web'
    web_config.vm.network "private_network", ip: "192.168.33.34"
    web_config.vm.synced_folder "web_config", "/web_config"
  end  
end

The app machine has an app_config folder and the web machine have a web_config folder(these folders are in the same level of the Vagrantfile file).

When you enter to each VM with the vagrant ssh command you can see each folder. This is into app machine.

roberto@rcisla-pc:~/Desktop/multiple$ vagrant ssh app
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Mon Jan 27 13:46:36 2014 from 10.0.2.2
vagrant@app:~$ cd /app_config/
vagrant@app:/app_config$ ls
app_config_file

This is into web machine.

roberto@rcisla-pc:~/Desktop/multiple$ vagrant ssh web
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Mon Jan 27 13:47:12 2014 from 10.0.2.2
vagrant@web:~$ cd /web_config/
vagrant@web:/web_config$ ls
web_config_file
vagrant@web:/web_config$

And this is the structure for my directory.

.
├── **app_config**
│   └── *app_config_file*
├── attributes
├── Berksfile
├── Berksfile.lock
├── chefignore
├── definitions
├── files
│   └── default
├── Gemfile
├── libraries
├── LICENSE
├── metadata.rb
├── providers
├── README.md
├── recipes
│   └── default.rb
├── resources
├── templates
│   └── default
├── test
│   └── integration
│       └── default
├── Thorfile
├── Vagrantfile
├── Vagrantfile~
└── **web_config**
    └── *web_config_file*

I hope this help you.

like image 60
Robert Avatar answered Apr 01 '23 04:04

Robert