I haven't been able to find a work around for this yet.
Issue:
The same Vagrantfile may be used to start multiple instances on the same machine. While vagrant-hostmanager works great at putting in the proper IP addresses, the issue is, if there's already a VM running with the hostname of 'vagrant-test', hostmanager will just add another entry in the hosts file with the same hostname. Which leaves me looking for a solution that will concatenate a prefix or suffix to the hostname, if one already exists.
So far my best idea is to detect the host OS, the based on the host OS, read the host file, checking for exists entries of the defined hostname in the vagrant file. If found add an incrementing prefix/suffix. Which should result in something like:
Just wondering if I'm completely missing a simple solution to do this, as I was considering modifying the hostmanager plugin locally to attempt to do this. Obviously I can easily do something like communicating to the host machine and running num=$(cat /etc/hosts | grep "emulator-api" | wc -l | sed -e 's/[\t ]//g;/^$/d') && sum=$(($num + 1)) && echo $sum(if the host machine is linux/osx) which brings me to the second issue I need this to work on both *nix OS's and Windows, I'm sure I can make a Windows equivalent, but again, there might be an easier way to accomplish this.
I haven't been able to find a work around for this yet.
Issue: The same Vagrantfile may be used to start multiple instances on the same machine. While vagrant-hostmanager works great at putting in the proper IP addresses, the issue is, if there's already a VM running with the hostname of 'vagrant-test', hostmanager will just add another entry in the hosts file with the same hostname. Which leaves me looking for a solution that will concatenate a prefix or suffix to the hostname, if one already exists.
Example:
So far my best idea is to detect the host OS, the based on the host OS, read the host file, checking for exists entries of the defined hostname in the vagrant file. If found add an incrementing prefix/suffix. Which should result in something like:
Just wondering if I'm completely missing a simple solution to do this, as I was considering modifying the hostmanager plugin locally to attempt to do this. Obviously I can easily do something like communicating to the host machine and running
num=$(cat /etc/hosts | grep "emulator-api" | wc -l | sed -e 's/[\t ]//g;/^$/d') && sum=$(($num + 1)) && echo $sum
(if the host machine is linux/osx) which brings me to the second issue I need this to work on both *nix OS's and Windows, I'm sure I can make a Windows equivalent, but again, there might be an easier way to accomplish this.What do you all suggest?