Vagrant tips and tricks - mhulse/mhulse.github.io GitHub Wiki

Ruby language

The Vagrantfile syntax is in the Ruby Programming Language.

Some helpful tips to get you started in editing and debugging a Vagrantfile:

  • Use double quoted strings when you need to do: "Hello #{var}"
  • Use puts ... to print debug messages to the console.

Multiple VMs in one Vagrantfile

Example Vagrantfile:

Vagrant.configure("2") do |config|

    config.vm.define "debbie" do |debbie|
        debbie.vm.box = "debian/jessie64"
        debbie.vm.network :forwarded_port, host: 80, guest: 80
        debbie.vm.network :forwarded_port, host: 81, guest: 8080
        debbie.vm.network :forwarded_port, host: 3306, guest: 3306
        debbie.vm.network :forwarded_port, host: 2299, guest: 22
        debbie.vm.provision "shell", inline: "echo Hello"
    end
    
    config.vm.define "cindy" do |cindy|
        cindy.vm.box = "bento/centos-7.2"
        cindy.vm.network :forwarded_port, host: 8888, guest: 88
        cindy.vm.network :forwarded_port, host: 8080, guest: 80
        cindy.vm.network :forwarded_port, host: 3333, guest: 3306
        cindy.vm.network :forwarded_port, host: 2298, guest: 22
        cindy.vm.provision "shell", inline: "echo Hello"
    end
    
    config.vm.define "chelsea" do |chelsea|
        # ...
    end
    
    config.vm.define "cathy" do |cathy|
        # ...
    end
    
end

Next, via command line:

$ vagrant up # All machines boot up. Then …
$ vagrant ssh cindy
# … or:
$ vagrant ssh debbie
# … etc.

Mounting VM as disk

Windows OS

Note: This is an example of how my coworker does this … If you used this approach for this Vagrant setup, you would need to modify the Vagrantfile.

Example Vagrantfile:

Vagrant.configure("2") do |config|

    config.vm.define "debbie" do |debbie|
        debbie.vm.box = "debian/jessie64"
        debbie.vm.network :forwarded_port, host: 80, guest: 80
        debbie.vm.network :forwarded_port, host: 81, guest: 8080
        debbie.vm.network :forwarded_port, host: 3306, guest: 3306
        debbie.vm.network :forwarded_port, host: 2299, guest: 22
        debbie.vm.provision "shell", inline: "echo Hello"
    end
    
    config.vm.define "cindy" do |cindy|
        cindy.vm.box = "bento/centos-7.2"
        cindy.vm.network :forwarded_port, host: 8888, guest: 88
        cindy.vm.network :forwarded_port, host: 8080, guest: 80
        cindy.vm.network :forwarded_port, host: 3333, guest: 3306
        cindy.vm.network :forwarded_port, host: 2298, guest: 22
        cindy.vm.provision "shell", inline: "echo Hello"
    end
    
    config.vm.define "chelsea" do |chelsea|
        # ...
    end
    
    config.vm.define "cathy" do |cathy|
        # ...
    end
    
end

Download and install SFTP Net Drive.

Create a debbie-ap.bat file on your desktop:

@echo off
Start "" "C:\Program Files (x86)\SFTP Net Drive 2017\Sftpnetdrive.exe" start /profile:"debbie"
Start "" "C:\Program Files (x86)\SFTP Net Drive 2017\Sftpnetdrive.exe" start /profile:"cindy"
Start "" "C:\Program Files (x86)\SFTP Net Drive 2017\Sftpnetdrive.exe" start /profile:"chelsea"
Start "" "C:\Program Files (x86)\SFTP Net Drive 2017\Sftpnetdrive.exe" start /profile:"cathy"

Mac OS

Download and install FUSE and SSHFS from FUSE for macOS.

... More information coming soon ...

Alternatively, you can use Transmit:

… once you have the server connection saved, select it, and choose Servers > Mount as Disk...

Connect to VM MySQL using SSH tunnel and MySQL Workbench

The following tip found here.

In MySQL Workbench (or any MySQL tool) select connection method (Standard TCP/IP over SSH).

Port is usually 2222 for vagrant SSH:

  • Hostname: 127.0.0.1:2222
  • Username: vagrant
  • SSH key file: /path/to/local/site/.vagrant/machines/default/virtualbox/private_key

Then enter your DB settings:

  • Hostname: 127.0.0.1
  • Port: 3306
  • Username: root

Links

⚠️ **GitHub.com Fallback** ⚠️