Search code examples
vagrantpuppetvagrantfilepuppetlabs-mysql

How to use vagrant in development and how to use shared folders?


I (a struggling newbie in vagrant) have done setup a vagrant environment for development. i have been provided with vagrant file

    Vagrant.configure("2") do |config|
      config.vm.box = 'precise64'
      config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
      config.vm.network :forwarded_port, guest: 80, host: 8080

      config.vm.provision :puppet do |puppet|
        puppet.module_path = "config/puppet/modules"
        puppet.manifests_path = "config/puppet/manifests"
        puppet.manifest_file = "base.pp"
      end

      config.vm.provider :virtualbox do |v|
        v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
      end
    end

the config/puppet/manifests contains following base.pp file

    Exec { 
      path => "/usr/bin:/bin:/usr/sbin:/sbin"
    }

    stage { 'first': 
      before => Stage['main']
    }

    class { 
      'system': stage => first; 
      'mysql':  stage => main;
      'apache': stage => main;
      'php':    stage=> main;
      'git':    stage=> main;
      'cake':   stage=> main;
    } 

and config/puppet/modules containing directories apache,cake,git,mysql,php and system.

What i did so far is

    1) Installed VirtualBox
    2) Installed Vagrant
    3) Vagrant up (as specified everywhere in net)

What i got is

    1) a virtualbox (having no GUI)
    2) SSH connection to virtaul box
    3) and a shared folder.

now i have some questions so that i can understand it well

    1) Am i going in right direction in order to setup vagrant?
    2) What is precise64.box(just console box), can't i add ubuntu as a box and everything set up(i.e. php, apache n other modules specified in puppet modules) in that ubuntu?
    3) Where does puppet install all these modules? in Host(Windows) or in Guest(precise64)?
    4) What config.vm.network :forwarded_port, guest: 80, host: 8080 do?
    5) what does shared folder do? and where does the shared folder reside in virtual box(precise64) and what i could/should do with this shared folder?
    6) where do i install Netbeans/Eclipse in order to develop my code?
    7) Any references/blog that describe vagrant and its advantages in and out?

I am trying to understand but couldn't figure it out how to understand vagrant (as a developer) and develop something. Any help or explanation would be appreciable and i guess these could be most common points that is hard for any newbie to understand.


Solution

  • 1) Yes, looks like you're doing everything right to me. There's really no right or wrong if it works, your config looks pretty standard. (Not sure about your puppet config...I've never used that)

    2) .box files are basically install cds that are packaged specifically for vagrant. In this case, you're downloading and installing http://files.vagrantup.com/precise64.box, which is essentially a bare-bones off the shelf ubuntu 12.04 64 bit server. You can find other prepackaged boxes here. The point of vagrant is to be able to start with a barebones OS and built it up by use of provisioning files (chef, puppet, bash, etc.).

    3) Everything in vagrant is very self contained within the VM its creating, I don't know much about puppet but I would assume it works much the same way that the bash provisioning files I use work. It boots the VM, then runs your provisioning scripts within the VM so that you have a reproducible VM creation process.

    4) Port forwarding. guest: 80, host :8080 means that anything within the VM (guest) serving on port 80 will be available on the host (your pc) at http://localhost:8080.

    5) Shared folders are AWESOME. Basically, your VM will have access to a folder from your host machine which is incredibly helpful for question number 6. Doing something like:

    config.vm.synced_folder "src/", "/vagrant"
    

    will make the src directory in your project (on the host) available to the vm at the mount point /vagrant. So you can have an IDE installed on your host, edit files in src and they'll automatically be available in your VM at /vagrant. More on that here.

    6) On your host machine. See answer to number 5. 7) Perhaps google is your best friend for this one. The biggest advantage for me is that we can check our Vagrantfile into our git repo next to the rest of our application code and any new member of our team can have the application running locally within minutes by navigating to the directory and running vagrant up. Mess something up within the VM and need to start fresh? vagrant destroy -> vagrant up. Not having to install a bunch of packages specific to an application on your host machine is invaluable.