view raw
ajhfleuwr ajhfleuwr - 10 months ago 37
Bash Question

How can I do computations on the fly within the vagrant file

How can I compute the hash on the fly within the vagrant file based on some input, for e.g. I do

# shell
$ echo "machine13" | sha256sum | cut -c1-12

# vagrantfile
Vagrant.configure(2) do |config|
config.vm.hostname = "machine13" "public_network", bridge: "eth0", use_dhcp_assigned_default_route: true, :mac => "2372240456c2"


If you just want to run a bash command and get its output to a variable in your Vagrantfile, you could use the ruby's back ticks to execute the command.

For example, your Vagrantfile:

# Vagrantfile
my_hostname = "machine12"
mac_hash = `echo #{my_hostname} | sha256sum | cut -c1-12`

Vagrant.configure(2) do |config|
  config.vm.hostname = my_hostname "public_network", bridge: "eth0", use_dhcp_assigned_default_route: true,  :mac => mac_hash