Vagrant - Message: undefined method `name'

13 views
Skip to first unread message

Sunil Gajula

unread,
Jan 16, 2019, 9:08:08 AM1/16/19
to Vagrant
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'

Alvaro Miranda Aguilera

unread,
Jan 16, 2019, 10:21:43 AM1/16/19
to vagra...@googlegroups.com
Hello

why you expect this to work? seems .name is not valid in machine

you already know the name of the box, "test-web"

why not use that?

also, you could use normal shell script to run the command in the VM and if there is any output, will be printed on the console.

Alvaro.

--
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 vagrant-up+...@googlegroups.com.
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.


--
Alvaro

Reply all
Reply to author
Forward
0 new messages