Create VM using Vagrant and Parallels provider
In the example:
- VM with name
example-vm-1
, 1G mem and 2 cpu will be created fromgutehall/fedora40
image (vagrant box) - User public key from host will be copied into vm
- Port 8500 VM will be binding and accessable from host
127.0.0.1:8500
- File
./config-file.yaml
will be uploaded into VM - Shell script
script.sh
will be executed in VM environment
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_ed25519.pub").first.strip
s.inline = <<-SHELL
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
SHELL
end
config.vm.define "example-vm-1" do |ev1|
ev1.vm.box = "gutehall/fedora40"
ev1.vm.provider "parallels" do |p|
p.memory = "1024"
p.cpus = "2"
end
ev1.vm.provision "upload-config-file", type: "file", source: "./config-file.yaml", destination: "~/config-file.yaml"
ev1.vm.provision "start-shell-script", after: "upload-config-file", type: "shell", path: "script.sh"
ev1.vm.hostname = "example-vm-1"
ev1.vm.network "forwarded_port", guest: 8500, host: 8500, host_ip: "127.0.0.1"
end
end