I’m not understanding this trigger, and probably not understanding iteration well. Can someone please point out what I’m doing wrong here. My expectation is each vm in sequence will reboot (reload) once the Vagrant process if fully complete. Each of the commented sections below haven’t worked. Some just silently fail, some render this message:
==> smar02: Machine is up!
smar02: Running local: Inline script
smar02: vagrant reload
smar02: An action 'reload' was attempted on the machine 'smar02',
smar02: but another process is already executing an action on the machine.
smar02: Vagrant locks each machine for access by only one process at a time.
smar02: Please wait until the other Vagrant process finishes modifying this
smar02: machine, then try again.
smar02:
smar02: If you believe this message is in error, please check the process
smar02: listing for any "ruby" or "vagrant" processes and kill them. Then
smar02: try again.
smar02:
==> smar02: Trigger run failed
==> smar02: A script exited with an unacceptable exit code 1.
A script exited with an unacceptable exit code 1.
Vagrantfile.yaml:
box_image: 'ubuntu-20.04_mini-20211220c'
interface: 'eno1'
systems:
smar02: ''
gcme02: ''
Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
current_dir = File.dirname(File.expand_path(__FILE__))
myconfigs = YAML.load_file("#{current_dir}/Vagrantfile.yaml")
myhostnames = myconfigs['systems']
myinterface = myconfigs['interface']
mybox_image = myconfigs['box_image']
Vagrant.configure("2") do |config|
myhostnames.each do |i,x|
#config.trigger.after [:provision] do |t|
# t.name = "Reboot after provisioning"
# t.run = { :inline => "vagrant reload" }
#end
config.vm.boot_timeout = 900
config.vm.define vm_name = "#{i}" do |subconfig|
subconfig.vm.box = mybox_image
subconfig.ssh.username = "vmadmin"
subconfig.ssh.password = "vmadmin"
subconfig.vm.hostname = "#{i}"
subconfig.vm.network :public_network, auto_config: false, bridge: myinterface
subconfig.vm.provider "virtualbox" do |v|
v.name = vm_name
v.customize ["modifyvm", :id, "--paravirtprovider", "kvm"]
v.customize ["modifyvm", :id, "--autostart-enabled", "on"]
v.customize ["modifyvm", :id, "--nictype1", "virtio"]
v.customize ["modifyvm", :id, "--nictype2", "virtio"]
end
subconfig.vm.provision "shell", inline: <<-SHELL
curl -so /tmp/netplan.yaml.sh http://192.168.1.25/kickstart/ubuntu/netplan.yaml.sh
curl -so /tmp/ansible.admin.sh http://192.168.1.25/kickstart/ubuntu/ansible.admin.sh
/bin/bash /tmp/netplan.yaml.sh
/bin/bash /tmp/ansible.admin.sh
/bin/touch /tmp/firstrun
SHELL
subconfig.trigger.after :up do |trigger|
trigger.name = "Finished Message"
trigger.info = "Machine is up!"
trigger.run = { :inline => "vagrant reload" }
end
#
# https://superuser.com/questions/1338429/how-do-i-reboot-a-vagrant-guest-from-a-provisioner
#
#subconfig.trigger.after [:provision] do |t|
# t.name = "Reboot after provisioning"
# t.run = { :inline => "vagrant reload" }
#end
#config.vm.provision :shell do |shell|
# shell.privileged = true
# shell.inline = 'echo rebooting'
# shell.reboot = true
#end
end
end
end