Skip to content

Instantly share code, notes, and snippets.

@fifteen3
Created November 18, 2013 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fifteen3/7531194 to your computer and use it in GitHub Desktop.
Save fifteen3/7531194 to your computer and use it in GitHub Desktop.
Vagrant Shell provisioner for returning the ip address of your vm.
#typically you need this for a dhcp public network setup
#with private networks you set the ip address but it is still useful
#to have this provisioner if you reload the vagrant file as it will remind
#you what the ip address is, so you can set it in your host file.
#use eth0 if the network is public, eth1 if the network is private
$network_interface = "eth0"
$display_ip_address = <<IP_ADDRESS
ipaddress=`/sbin/ifconfig #{$network_interface} | grep 'inet addr' | awk -F' ' '{print $2}' | awk -F':' '{print $2}'`
echo "ip address: $ipaddress"
IP_ADDRESS
config.vm.provision "shell", inline: $display_ip_address
@fifteen3
Copy link
Author

to execute this script while the vm is running I can always run:

vagrant provvision --provision-with shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment