Difference between revisions of "Vagrant"

From Christoph's Personal Wiki
Jump to: navigation, search
(Created page with "'''Vagrant''' is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker co...")
 
(Vagrant commands)
 
Line 1: Line 1:
 
'''Vagrant''' is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. It tries to simplify the software configuration management of virtualization in order to increase development productivity. Vagrant is written in the Ruby language, but its ecosystem supports development in a few other languages.
 
'''Vagrant''' is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. It tries to simplify the software configuration management of virtualization in order to increase development productivity. Vagrant is written in the Ruby language, but its ecosystem supports development in a few other languages.
  
==Vagrant commands==
+
==Common Vagrant commands==
  
*<code>vagrant up</code> &mdash; Bring a box online.
+
* <code>autocomplete</code> &mdash; manages autocomplete installation on host
*<code>vagrant status</code> &mdash; Show current box status.
+
* <code>box</code> &mdash; manages boxes: installation, removal, etc.
*<code>vagrant suspend</code> &mdash; Pause the current box.
+
* <code>cloud</code> &mdash; manages everything related to Vagrant Cloud
*<code>vagrant resume</code> &mdash; Resume the current box.
+
* <code>destroy</code> &mdash; stops and deletes all traces of the vagrant machine
*<code>vagrant halt</code> &mdash; Shutdown the current box.
+
* <code>global-status</code> &mdash; outputs status Vagrant environments for this user
*<code>vagrant destroy</code> &mdash; Destroy the current box. By running this command, you will lose any data stored on the box.
+
* <code>halt</code> &mdash; stops the vagrant machine
*<code>vagrant snapshot</code> &mdash; Take a snapshot of the current box.
+
* <code>help</code> &mdash; shows the help for a subcommand
 +
* <code>init</code> &mdash; initializes a new Vagrant environment by creating a Vagrantfile
 +
* <code>login</code>
 +
* <code>package</code> &mdash; packages a running vagrant environment into a box
 +
* <code>plugin</code> &mdash; manages plugins: install, uninstall, update, etc.
 +
* <code>port</code> &mdash; displays information about guest port mappings
 +
* <code>powershell</code> &mdash; connects to machine via powershell remoting
 +
* <code>provision</code> &mdash; provisions the vagrant machine
 +
* <code>push</code> &mdash; deploys code in this environment to a configured destination
 +
* <code>rdp</code> &mdash; connects to machine via RDP
 +
* <code>reload</code> &mdash; restarts vagrant machine, loads new Vagrantfile configuration
 +
* <code>resume</code> &mdash; resume a suspended vagrant machine
 +
* <code>snapshot</code> &mdash; manages snapshots: saving, restoring, etc.
 +
* <code>ssh</code> &mdash; connects to machine via SSH
 +
* <code>ssh-config</code> &mdash; outputs OpenSSH valid configuration to connect to the machine
 +
* <code>status</code> &mdash; outputs status of the vagrant machine
 +
* <code>suspend</code> &mdash; suspends the machine
 +
* <code>up</code> &mdash; starts and provisions the vagrant environment
 +
* <code>upload</code> &mdash; upload to machine via communicator
 +
* <code>validate</code> &mdash; validates the Vagrantfile
 +
* <code>version</code> &mdash; prints current and latest Vagrant version
 +
* <code>winrm</code> &mdash; executes commands on a machine via WinRM
 +
* <code>winrm-config</code> &mdash; outputs WinRM configuration to connect to the machine
 +
 
 +
;Full list of available vagrant commands:
 +
$ vagrant list-commands
  
 
==Examples==
 
==Examples==

Latest revision as of 22:45, 21 September 2021

Vagrant is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. It tries to simplify the software configuration management of virtualization in order to increase development productivity. Vagrant is written in the Ruby language, but its ecosystem supports development in a few other languages.

Common Vagrant commands

  • autocomplete — manages autocomplete installation on host
  • box — manages boxes: installation, removal, etc.
  • cloud — manages everything related to Vagrant Cloud
  • destroy — stops and deletes all traces of the vagrant machine
  • global-status — outputs status Vagrant environments for this user
  • halt — stops the vagrant machine
  • help — shows the help for a subcommand
  • init — initializes a new Vagrant environment by creating a Vagrantfile
  • login
  • package — packages a running vagrant environment into a box
  • plugin — manages plugins: install, uninstall, update, etc.
  • port — displays information about guest port mappings
  • powershell — connects to machine via powershell remoting
  • provision — provisions the vagrant machine
  • push — deploys code in this environment to a configured destination
  • rdp — connects to machine via RDP
  • reload — restarts vagrant machine, loads new Vagrantfile configuration
  • resume — resume a suspended vagrant machine
  • snapshot — manages snapshots: saving, restoring, etc.
  • ssh — connects to machine via SSH
  • ssh-config — outputs OpenSSH valid configuration to connect to the machine
  • status — outputs status of the vagrant machine
  • suspend — suspends the machine
  • up — starts and provisions the vagrant environment
  • upload — upload to machine via communicator
  • validate — validates the Vagrantfile
  • version — prints current and latest Vagrant version
  • winrm — executes commands on a machine via WinRM
  • winrm-config — outputs WinRM configuration to connect to the machine
Full list of available vagrant commands
$ vagrant list-commands

Examples

Rancher

The following is an example of bringing up Rancher (pre-v2.x):

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

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

MASTER_MEMORY=1024
AGENT_MEMORY=1024

RANCH_MASTER_ADDRESS="172.19.8.100"
# Boxes are configured at 101, 102 and so on
RANCH_SUBNET="172.19.8"


RANCHER_SERVER_DOMAIN_NAME="ranch-svr.infracloud.io"
RANCHER_CLIENT_DEF="ranch-def.infracloud.io"
RANCHER_CLIENT_K8S="ranch-k8s.infracloud.io"


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    config.vm.define "ranch_server" do |rserver|
        rserver.vm.box = "ubuntu/xenial64"
        rserver.vm.network "private_network", ip: "#{RANCH_MASTER_ADDRESS}" 
        rserver.vm.hostname = "#{RANCHER_SERVER_DOMAIN_NAME}"
        rserver.vm.provider :virtualbox do |vba|
            vba.customize ["modifyvm", :id, "--memory", MASTER_MEMORY]
        end
        rserver.vm.provision "shell", inline: "wget -qO- https://get.docker.com/ | sh"          
        rserver.vm.provision "shell", inline: "sudo docker run -d --restart=always -p 8080:8080 rancher/server"     
    end

    config.vm.define "ranch_c_default" do |rclient|
        rclient.vm.box = "ubuntu/xenial64"
        rclient.vm.network "private_network", ip: "#{RANCH_SUBNET}.101"
        rclient.vm.hostname = "#{RANCHER_CLIENT_DEF}"
        rclient.vm.provider :virtualbox do |vba|
            vba.customize ["modifyvm", :id, "--memory", AGENT_MEMORY]
        end
        rclient.vm.provision "shell", inline: "wget -qO- https://get.docker.com/ | sh"      
        # K8S works with slightly older version of Docker hence downgrading
        #rclient.vm.provision "shell", inline: "sudo apt-get install -y --force-yes docker-engine=1.10.3-0~trusty"       
    end

    config.vm.define "ranch_c_k8s" do |rclient|
        rclient.vm.box = "ubuntu/xenial64"
        rclient.vm.network "private_network", ip: "#{RANCH_SUBNET}.102"
        rclient.vm.hostname = "#{RANCHER_CLIENT_K8S}"
        rclient.vm.provider :virtualbox do |vba|
            vba.customize ["modifyvm", :id, "--memory", AGENT_MEMORY]
        end
        rclient.vm.provision "shell", inline: "wget -qO- https://get.docker.com/ | sh"
        # K8S works with slightly older version of Docker hence downgrading
        #rclient.vm.provision "shell", inline: "sudo apt-get install -y --force-yes docker-engine=1.10.3-0~trusty"
    end

end
  • Start up resources:
$ vagrant up

External links