0

I have a RHEL image already preconfigured, I don't know how it was originally setup. By default, it is configured with a local network interface on the ip 192.168.50.50. What I am trying to do is configure its ip from the Vagrant script.

This doesn't seem to do anything:

config.vm.network "private_network", ip: "192.168.50.10"

This does change the ip:

sudo nmcli con mod bond0 ipv4.addresses 192.168.50.10/24
service network restart

But after that apparently Vagrant doesn't automatically detect the ip to connect to, so I need to add:

config.ssh.host = LOCAL_IP

But here's the problem: on the first time, the ip is the default one (.50.50). So I can't already set config.ssh.host to my desired ip. If I omit the config.ssh.host line, it runs the first time but not after, and vagrant ssh fails as well.

Is there a way to set the box ip without editing the Vagrant script between the first and second vagrant up?


Edit: Result of vagrant up --debug command: http://pastebin.com/BTccc4NT


Edit: The problem was that the Vagrant file from the default box (on Windows, it's at C:\Users\user\.vagrant.d\boxes\nameofbox\virtualbox\Vagrantfile) itself had this line:

config.vm.network "private_network", ip: "192.168.50.50", auto_config: false
2
  • normally config.vm.network "private_network", ip: "192.168.50.10" should do the trick so there might be something else, do you have a provision script that force the ip ? can you run vagrant up --debug &> vagrant.log and post the log file somewhere on pastebin (the file will be really large but will detail if the right commands are run correctly) Commented Sep 26, 2016 at 9:23
  • Thanks. I've attached the log. I'm not in a position to do additional investigation on it right now, I'll do tomorrow. I can see the 192.168.50.10 string appear in the log, but can't really tell what it means.
    – trethaller
    Commented Sep 26, 2016 at 16:43

1 Answer 1

1
+50

hum, its weird, it creates 2 interfaces

DEBUG network: Normalized configuration: {:adapter_ip=>"192.168.50.1", :auto_config=>false, :ip=>"192.168.50.50", :mac=>nil, :name=>nil, :netmask=>"255.255.255.0", :nic_type=>nil, :type=>:static, :adapter=>2}
 INFO network: Searching for matching hostonly network: 192.168.50.50
 INFO subprocess: Starting process: ["C:/Program Files/Oracle/VirtualBox/VBoxManage.exe", "list", "hostonlyifs"]

......

DEBUG network: Normalized configuration: {:adapter_ip=>"192.168.50.1", :auto_config=>true, :ip=>"192.168.50.10", :mac=>nil, :name=>nil, :netmask=>"255.255.255.0", :nic_type=>nil, :type=>:static, :adapter=>3}
 INFO network: Searching for matching hostonly network: 192.168.50.10
 INFO subprocess: Starting process: ["C:/Program Files/Oracle/VirtualBox/VBoxManage.exe", "list", "hostonlyifs"]

so on on adapter2 you have 192.168.50.50 and on adapter3 you have 192.168.50.10

The possible reason for this is that the box you're using has a specific Vagrantfile which defines already a network on the static address.

I am not fully familiar with windows but on mac, the box definition is under ~/.vagrant/boxes/<yourbox>/<theprovider>/Vagrantfile (note this is not the Vagrantfile from your project, this is really a Vagrantfile which will be applied to any VM built from this box); check the file and remove the network configuration if you see it

As documented the Vagrantfile are merged from the different locations

At each level, settings set will be merged with previous values. What this exactly means depends on the setting. For most settings, this means that the newer setting overrides the older one. However, for things such as defining networks, the networks are actually appended to each other. By default, you should assume that settings will override each other. If the behavior is different, it will be noted in the relevant documentation section.

so by default Vagrant will create additional network interface and will not replace the one coming from the box Vagrantfile.

6
  • You're right, there is indeed a hardcoded IP there. Is there any way to override it without repackaging the box? Those boxes are maintained by another team and it would be more convenient.
    – trethaller
    Commented Sep 27, 2016 at 8:03
  • you can override the Vagrantfile from the box folder, it will change on your local, and there's no issue about that - the other folks that will use the box will not be impacted by your local change; but all will run by default on the 50.50 IP Commented Sep 27, 2016 at 8:10
  • Sorry I meant, if I want to share this with my team, is there a way to override this directly in the user Vagrantfile, or do I have to repackage a box without the hardcoded 192.168.50.50 line? (Btw, thanks for helping solve the problem, I'll award the bounty when SO lets me)
    – trethaller
    Commented Sep 27, 2016 at 8:18
  • hum I am not sure you can do that - adding some doc part ; I would be able to try later today, best would probably to remove the box Vagrantfile (or at least this setting) and repackage the box Commented Sep 27, 2016 at 8:30
  • It still doesn't work, even after deleting the line in the base Vagrantfile. I can see that the line about 192.168.50.50 is gone in the debug log (actually there isn't any occurrence of the "50.50" string), and my new IP appears, but the box still gets up with 192.168.50.50. The bond0 connection is still there with IP 192.168.50.50.
    – trethaller
    Commented Sep 27, 2016 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.