I am creating a VirtualBox machine with Vagrant. In the provisioning I need to know the IP address of the box that was assigned by the VirtualBox DHCP. Is there any way to use that assigned IP address in the Vagrantfile?
Vagrant.configure(2) do |config|
# ... some more config
config.vm.network "private_network", type: "dhcp"
# ... some more config
config.vm.provision "shell", inline: <<-SHELL
sudo -i /vagrant/my_provisioning_script.sh <insert ip here>
SHELL
end
You can do an
ifconfig
inside the vagrant box to get the ips of your box; should be the ip in eth0, but since you need it on the provisioning and you are using shell you could do:In my vagrant box this outputs
so your command could be
I tried the above with ping.
Also you can define the ip if you want, edit your Vagrantfile and add:
this will assign that ip to your box. and if you do
ifconfig
it will be listed on eth1. So you could hardcode the ip on your script.