I'm trying to set up my Vagrantfile so that it appends the current date and time to the hostname.
This works on Mac OS but not on Windows. Is there some other way for me to do this?
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
## THIS IS THE VAGRANTFILE FOR GENERIC 'my-linux-vm'
username = `whoami`.chomp # you need chomp as the result of the command executed this way returns \n at the end
myDate = `date +%Y-%m-%d-%H.%M.%S`.chomp
myhostname = "#{username}-linux-vm-#{myDate}"
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.provision :shell, path: "install-extras.sh"
# this works:
config.vm.hostname = "#{myhostname}"
config.vm.provider "virtualbox" do |v|
end
config.trigger.after :up do |updatePkgs|
updatePkgs.warn = "Checking for software updates"
updatePkgs.run_remote = {inline: "apt-get --with-new-pkgs upgrade -y"}
end
config.vm.synced_folder "./shared", "/shared", create: true
end