Vagrant ist ein in Ruby geschriebenes Open-Source (MIT) Kommandozeilen-Programm, das euch dass Erstellen und Verwalten von virtuellen Testmaschinen extrem vereinfachen soll. Virtuelle Maschinen können durch Vorlagen (Vagrantfiles) automatisiert installiert und durchkonfiguriert werden.
Vagrant ermöglicht übelst einfaches Deployment, insbesondere in der Software- und Webentwicklung. Das Tool dient als Wrapper zwischen Virtualisierungssoftware wie VirtualBox, VMware, Hyper-V und Software-Configuration-Management-Anwendungen beziehungsweise Systemkonfigurationswerkzeugen wie Ansible, Chef, Saltstack und Puppet.
Die Dokumentation ist rattenscharf und als Leckerlie obendrauf gibt es hier vorgefertigte Vagrant Template-Pakete.
Einfache Einrichtung einer Ubuntu 20.04 LTS VM
Folgendem Befehle abfeuern und eine Ubuntu 20.04 LTS VM ist Startklar zum Entern:
vagrant init ubuntu/focal64 vagrant-up
Vagrant steuern
# Vagrant-Box initialisieren vagrant init vagrant init ubuntu/focal64 # Vagrant-Box starten vagrant up # Vagrant-Box ssh vagrant ssh-config vagrant ssh # Vagrant-Box stoppen vagrant halt # Vagrant-Box updaten vagrant box update # Vagrant-Box löschen vagrant destroy -f # Vagrant-Box Status anzeigen vagrant status # Required after changes made in the Vagrantfile to take effect vagrant reload # Create Snapshot vagrant snapshot save # Restore Snapshot vagrant snapshot pop
Beispiel – Einrichtung einer Ansible-Testumgebung
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider :virtualbox do |vb|
vb.cpus = "2"
vb.memory = 2048
vb.linked_clone = true
end
# VM - Master-Node
config.vm.define "node-master" do |node|
node.vm.hostname = "node-master"
node.vm.network "private_network", ip: "192.168.30.10"
node.vm.provision "shell", inline: <<-SHELL
sudo apt -q -y update --fix-missing
sudo apt -q -y install acl apg apt-transport-https bzip2 curl less liblz4-tool moreutils net-tools python3-pip psmisc psutils screen sshpass traceroute unzip zip vim
sudo pip3 install ansible
sudo mkdir -p ~/ansible/{inventories,playbooks,roles/role_template/{defaults,files,handlers,meta,tasks,templates,vars}}
sudo echo -e "192.168.30.10 node-master master 192.168.30.11 node-1 node1 192.168.30.12 node-2 node2" >> /etc/hosts
ssh-keygen -o -a 100 -t ed25519 -N "" -f ~/.ssh/ssh_ansible_ed25519_key -C "$(whoami)@$(hostname)-$(date -I)"
SHELL
node.vm.provider "virtualbox" do |vb|
vb.name = "node-master"
end
end
# VM - node 1
config.vm.define "node-1" do |node|
node.vm.hostname = "node-1"
node.vm.network "private_network", ip: "192.168.30.11"
node.vm.provision "shell", inline: <<-SHELL
sudo apt -q -y update --fix-missing
SHELL
node.vm.provider "virtualbox" do |vb|
vb.name = "node-1"
end
end
# VM - Node 2
config.vm.define "node-2" do |node|
node.vm.hostname = "node-2"
node.vm.network "private_network", ip: "192.168.30.12"
node.vm.provision "shell", inline: <<-SHELL
sudo apt -q -y update --fix-missing
SHELL
node.vm.provider "virtualbox" do |vb|
vb.name = "node-2"
end
end
end


