Skip to content

VikasChoataHP/vagrant-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vagrant Tutorial: Creating Development Environments with VMware Fusion

Vagrant is a powerful tool for creating and managing virtualized development environments. It allows developers to standardize and automate the setup of environments, reducing issues caused by differences between development, staging, and production systems. This tutorial will guide you through setting up Vagrant with VMware Fusion to create a reusable and shareable development environment.


Prerequisites

Before starting, ensure you have the following installed:

  • VMware Fusion: A virtualization tool for running virtual machines on macOS.
  • Vagrant: The main tool used for environment automation.
  • Vagrant VMware Utility: A plugin required to enable VMware support in Vagrant.
  • A terminal application (e.g., Terminal, iTerm2).

Step 1: Install VMware Fusion and Vagrant

  1. Download and install both VMware Fusion and Vagrant from their respective websites:

  2. Install the Vagrant VMware Utility

  3. Verify the installation:

    vagrant --version
    vmrun -v

    If both commands respond without errors, you're ready to proceed.

  4. Install the Vagrant VMware provider plugin

    vagrant plugin install vagrant-vmware-desktop

Step 2: Create Vagrant Project

  1. Create a new directory for your project:

    mkdir vagrant-vmware-lab
    cd vagrant-vmware-lab
  2. Initialize a new Vagrantfile:

    vagrant init

This will generate a Vagrantfile, which contains the configuration for your Vagrant environment.


Step 3: Configure the Vagrantfile

  1. Open the Vagrantfile in a text editor.

  2. Modify it to suit your needs. For example, to use Ubuntu 20.04 as your base box and configure VMware Fusion, update the file like this:

    Vagrant.configure("2") do |config|
      config.vm.box = "ubuntu/jammy64"
      config.vm.network "private_network", type: "dhcp"
      config.vm.provider "vmware_desktop" do |v|
        v.memory = "1024"
        v.cpus = 2
      end
    end

Explanation

  • config.vm.box: Specifies the base image ("box") to use.
  • config.vm.network: Sets up network configurations (e.g., private network).
  • config.vm.provider: Configures provider-specific settings (e.g., VMware Fusion settings like memory and CPU).

Step 4: Start the Virtual Machine

  1. Run the following command to start the virtual machine:

    vagrant up --provider vmware_desktop

    Vagrant will download the base box if it's not already cached and configure the virtual machine as specified in the Vagrantfile.

  2. SSH into the machine:

    vagrant ssh

    This connects you to the VM's terminal.


Step 5: Provision the Environment

Vagrant allows you to automate the installation of software and configuration through provisioning scripts.

  1. Add a provisioning script to your project, e.g., provision.sh:

    sudo apt update
    sudo apt install -y software-properties-common
    sudo add-apt-repository --yes --update ppa:ansible/ansible
    sudo apt install -y ansible
  2. Update the Vagrantfile to include the script:

    config.vm.provision "shell", path: "provision.sh"
  3. Re-provision the machine:

    vagrant provision

    The Ansible packages will be available on the machine.


Step 6: Access Shared Folders

By default, Vagrant syncs the project directory on your host machine with /vagrant in the guest VM. This makes it easy to share files between the host and the virtual machine.

  • On the host: Place files in your project directory.
  • In the VM: Access them under /vagrant.

Manage Virtual Machines

Some common Vagrant commands:

  • vagrant up: Start the virtual machine.
  • vagrant ssh: SSH into the VM.
  • vagrant halt: Stop the VM.
  • vagrant destroy: Delete the VM.
  • vagrant reload: Restart the VM and apply configuration changes.

References

About

Vagrant Hands-on tutorials for @VCTechTalks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages