Difference between revisions of "Vagrant"

From ArchWiki
Jump to navigation Jump to search
(Updated with working fix for 1.8.1)
(vagrant-libvirt)
Line 33: Line 33:
  
 
This plugin adds [[Libvirt]] support.
 
This plugin adds [[Libvirt]] support.
 +
Unfortunately, we have to use Vagrant's embedded version of Ruby to avoid RubyGem Native Extension version conflicts.
  
 
As of vagrant 1.8.1, this invocation will install vagrant-libvirt successfully:
 
As of vagrant 1.8.1, this invocation will install vagrant-libvirt successfully:
  
 +
  # in case it's already installled
 
   vagrant plugin uninstall vagrant-libvirt
 
   vagrant plugin uninstall vagrant-libvirt
 
    
 
    
Line 45: Line 47:
 
    
 
    
 
   CONFIGURE_ARGS="with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib" vagrant plugin install vagrant-libvirt
 
   CONFIGURE_ARGS="with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib" vagrant plugin install vagrant-libvirt
 
 
  # put vagrant's copy of curl back
 
  sudo mv /opt/vagrant/embedded/lib/libcurl.so{.backup,}
 
  sudo mv /opt/vagrant/embedded/lib/libcurl.so.4{.backup,}
 
  sudo mv /opt/vagrant/embedded/lib/libcurl.so.4.4.0{.backup,}
 
  sudo mv /opt/vagrant/embedded/lib/pkgconfig/libcurl.pc{.backup,}
 
 
    
 
    
 
   # https://github.com/pradels/vagrant-libvirt/issues/541
 
   # https://github.com/pradels/vagrant-libvirt/issues/541
Line 57: Line 53:
 
   export GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems
 
   export GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems
 
   gem uninstall ruby-libvirt
 
   gem uninstall ruby-libvirt
  sudo mv /opt/vagrant/embedded/lib/libcurl.so{,.backup}
 
  sudo mv /opt/vagrant/embedded/lib/libcurl.so.4{,.backup}
 
  sudo mv /opt/vagrant/embedded/lib/libcurl.so.4.4.0{,.backup}
 
  sudo mv /opt/vagrant/embedded/lib/pkgconfig/libcurl.pc{,.backup}
 
 
   gem install ruby-libvirt
 
   gem install ruby-libvirt
 +
 
 +
  # put vagrant's copy of curl back
 
   sudo mv /opt/vagrant/embedded/lib/libcurl.so{.backup,}
 
   sudo mv /opt/vagrant/embedded/lib/libcurl.so{.backup,}
 
   sudo mv /opt/vagrant/embedded/lib/libcurl.so.4{.backup,}
 
   sudo mv /opt/vagrant/embedded/lib/libcurl.so.4{.backup,}
 
   sudo mv /opt/vagrant/embedded/lib/libcurl.so.4.4.0{.backup,}
 
   sudo mv /opt/vagrant/embedded/lib/libcurl.so.4.4.0{.backup,}
 
   sudo mv /opt/vagrant/embedded/lib/pkgconfig/libcurl.pc{.backup,}
 
   sudo mv /opt/vagrant/embedded/lib/pkgconfig/libcurl.pc{.backup,}
 +
 +
 +
[https://gist.github.com/robled/070e1922816bbe983623#file-reinstall-vagrant-libvirt-sh Source]
  
 
Then start the virtual machine with
 
Then start the virtual machine with

Revision as of 16:08, 27 February 2016

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements. See Help:Style for reference.Tango-edit-clear.png

Reason: Several style issues, see Help:Style and related. (Discuss in Talk:Vagrant#)

Vagrant is a tool for managing and configuring virtualised development environments.

Vagrant has a concept of 'providers', which map to the virtualisation engine and its API. The most popular and well-supported provider is Virtualbox; plugins exist for libvirt, kvm, lxc, vmware and more.

Vagrant uses a mostly declarative Vagrantfile to define virtualised machines. A single Vagrantfile can define multiple machines.

See also Wikipedia:Vagrant (software).

Installing Vagrant

Install vagrant from the official repositories.

Plugins

Vagrant has a middleware architecture providing support for powerful plugins.

Plugins can be installed with Vagrant's built-in plugin manager. You can specify multiple plugins to install:

vagrant plugin install vagrant-vbguest vagrant-share

vagrant-libvirt

This plugin adds Libvirt support. Unfortunately, we have to use Vagrant's embedded version of Ruby to avoid RubyGem Native Extension version conflicts.

As of vagrant 1.8.1, this invocation will install vagrant-libvirt successfully:

 # in case it's already installled
 vagrant plugin uninstall vagrant-libvirt
 
 # vagrant's copy of curl prevents the proper installation of ruby-libvirt
 sudo mv /opt/vagrant/embedded/lib/libcurl.so{,.backup}
 sudo mv /opt/vagrant/embedded/lib/libcurl.so.4{,.backup}
 sudo mv /opt/vagrant/embedded/lib/libcurl.so.4.4.0{,.backup}
 sudo mv /opt/vagrant/embedded/lib/pkgconfig/libcurl.pc{,.backup}
 
 CONFIGURE_ARGS="with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib" vagrant plugin install vagrant-libvirt
 
 # https://github.com/pradels/vagrant-libvirt/issues/541
 export PATH=/opt/vagrant/embedded/bin:$PATH
 export GEM_HOME=~/.vagrant.d/gems
 export GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems
 gem uninstall ruby-libvirt
 gem install ruby-libvirt
 
 # put vagrant's copy of curl back
 sudo mv /opt/vagrant/embedded/lib/libcurl.so{.backup,}
 sudo mv /opt/vagrant/embedded/lib/libcurl.so.4{.backup,}
 sudo mv /opt/vagrant/embedded/lib/libcurl.so.4.4.0{.backup,}
 sudo mv /opt/vagrant/embedded/lib/pkgconfig/libcurl.pc{.backup,}


Source

Then start the virtual machine with

 vagrant up --provider=libvirt

vagrant-lxc

First install lxc from the official repositories, then:

vagrant plugin install vagrant-lxc

Next, configure lxc and some systemd unit files per this comment. The plugin can now be used with a Vagrantfile like so:

VAGRANTFILE_API_VERSION = "2"

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

    config.vm.define "main" do |config|
        config.vm.box = 'http://bit.ly/vagrant-lxc-wheezy64-2013-10-23'

        config.vm.provider :lxc do |lxc|
            lxc.customize 'cgroup.memory.limit_in_bytes', '512M'
        end

        config.vm.provision :shell do |shell|
            shell.path = 'provision.sh'
        end
    end
end

The provision.sh file should be a shell script beside the Vagrantfile. Do whatever setup is appropriate; for example, to remove puppet, which is packaged in the above box:

rm /etc/apt/sources.list.d/puppetlabs.list
apt-get purge -y puppet facter hiera puppet-common puppetlabs-release ruby-rgen

vagrant-kvm (deprecated)

This plugin supports KVM as the virtualisation provider.

Vagrant installs a self-contained rainbow environment in /opt which interacts with the system Ruby and other libraries in Arch in confusing ways (Issue with Ruby, Issue with Curl library).

Please see and follow the complete installation guide for Arch Linux at vagrant-kvm wiki.

Provisioning

Provisioners allow you to automatically install software, alter and automate configurations as part of the vagrant up process. The two most common provisioners are puppet from official repositories and chefAUR[broken link: archived in aur-mirror] from the AUR Arch User Repository.

Base Boxes for Vagrant

Here is a list of places to get all sorts of vagrant base boxes for different purposes: development, testing, or even production.

  • The same Arch Linux x86_64 base box can also be obtained via Vagrant Cloud by running: vagrant init terrywang/archlinux
  • Vagrant Cloud is HashiCorp's official site for Vagrant boxes. You can browse user-submitted boxes or upload your own. A single Vagrant Cloud box can support multiple providers with versioning.
  • Opscode bento
    We all know what bento means in Japanese, right? In this case, they are NOT lunch boxes BUT extremely useful base boxes which can be used to test cookbooks or private chef (Chef Server and Client). Distributions included: Ubuntu Server, Debian, CentOS, Fedora and FreeBSD.
  • Vagrant Ubuntu Cloud Images
    It has been there since Jan, 2013. For some reason Canonical has NOT officially promoted it yet, may be still in beta. Remember these are vanilla images, NOT very useful without Chef or Puppet.

Troubleshooting

No ping between host and vagrant box (host-only networking)

Sometimes there are troubles with host-only networking not functioning. Host have no ip on vboxnet interface, host cannot ping vagrant boxes and cannot be pinged from them. This is solved by installing good old net-tools as mentioned in this thread by kevin1024

'vagrant up' hangs on NFS mounting (Mounting NFS shared folders...)

Installing net-tools package may solve this problem.

See also