I am invoking the below Vagrant code to get the IP address. I am using DHCP
to use a private network and allow the IP to be assigned via DHCP.
# Vagrantfile
Vagrant.configure(2) do |config|
config.ssh.insert_key = true
config.ssh.username = "vagrant"
config.vm.network "private_network", type: "dhcp"
config.vm.box = "ubuntu/trusty64"
config.vm.define "test-web"
config.trigger.after :up, :stdout => false, :stderr => false do
get_ip_address = %Q(vagrant ssh #{@machine.name} -c 'ifconfig | grep
-oP "inet addr:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}" | grep -oP
"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}" | tail -n 2 | head -n 1')
@logger.debug "Running `#{get_ip_address}`"
output = `#{get_ip_address}`
@logger.debug "Output received:\n----\n#{output}\n----"
puts "==> #{@machine.name}: Available on DHCP IP address
#{output.strip}"
@logger.debug "Finished running :after trigger"
end
end
When I validate the code, I get the below error? Looks like some issue with
@machine.name.
vagrant validate
Vagrant failed to initialize at a very early stage:
There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
an invalid or undefined variable.
Path: /Users/Vagrantfile
Line number: 0
Message: undefined method `name'
--
This mailing list is governed under the HashiCorp Community Guidelines -
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of
those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vagrant-up/d3945796-c65a-4d80-9e57-a6c41f43caa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.