Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

vagrant

Make and destroy local virtual machines from one file — a repeatable lab for Linux, Ansible and RHCSA practice.

Niveau
DevOps-tool
Groep
Infrastructuur als code en cloud
Root nodig
Nee
Pakket
vagrant

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

vagrant reads a Vagrantfile that describes one or more VMs: the base box (an OS image), CPU, memory, network and how to set them up (provisioning with a shell script or Ansible). vagrant up builds them; vagrant destroy throws them away. The same lab works on every laptop.

Providers: VirtualBox, libvirt/KVM, Hyper-V, VMware.

Zo schrijf je het

vagrant COMMAND [VM] [OPTIONS]

Belangrijkste delen

Commands

init BOX
Make a Vagrantfile for a box.
up [VM]
Create and start the VMs.
ssh [VM]
Log in.
halt / reload / suspend / resume
Stop / restart / pause / continue.
destroy [-f]
Delete the VMs.
provision
Run the provisioning again.
status / global-status
State of the VMs here / everywhere.
snapshot save|restore|list NAME
Snapshots.
box add|list|update|remove
Manage boxes.
ssh-config
SSH settings (for ssh or Ansible).

Opties 4

Meest gebruikt

Options

--provider libvirt|virtualbox
Choose the provider.
--provision / --no-provision
Run / skip provisioning with up or reload.
-f, --force
Do not ask (destroy).
--prune
Clean global-status.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1A first VM

    vagrant init generic/rocky9
    vagrant up
    vagrant ssh
  2. 2Two servers for an RHCSA lab

    cat Vagrantfile
    Vagrant.configure("2") do |config|
      config.vm.box = "generic/rocky9"
      %w[server1 server2].each_with_index do |name, i|
        config.vm.define name do |s|
          s.vm.hostname = "#{name}.example.com"
          s.vm.network "private_network", ip: "192.168.56.#{10 + i}"
          s.vm.provider "virtualbox" do |v| v.memory = 2048; v.cpus = 2 end
        end
      end
    end
    vagrant up
  3. 3Provision with Ansible

    cat Vagrantfile
    config.vm.provision "ansible" do |a|
      a.playbook = "site.yml"
    end
    vagrant provision
  4. 4Snapshot before a risky exercise

    vagrant snapshot save server1 clean
    vagrant snapshot restore server1 clean
  5. 5Use KVM instead of VirtualBox

    vagrant up --provider libvirt
  6. 6SSH config for normal ssh and Ansible inventory

    vagrant ssh-config > ssh.cfg
    ssh -F ssh.cfg server1
  7. 7Status of all VMs on this machine

    vagrant global-status --prune
  8. 8Restart and apply Vagrantfile changes

    vagrant reload --provision
  9. 9Stop at night, delete when done

    vagrant halt
    vagrant destroy -f
  10. 10Update the base box

    vagrant box update

Let op

  • Public boxes are made by others; use boxes from known publishers (generic/, bento/, rockylinux/).
  • The default vagrant user has the insecure public key at first boot — never expose a lab VM to the internet.

Bestanden

Vagrantfile
The VM description (Ruby).
.vagrant/
Local state; add to .gitignore.
~/.vagrant.d/boxes/
Downloaded boxes.

Tips om te onthouden

  • Vagrant + Ansible is a great way to test playbooks before they touch real servers.

Exitcodes

0OK.
1Error.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man vagrant