Closed ajxb closed 3 years ago
Yes we removed that behaviour some release ago and the readme specify to use the alias parameters (that can include just one domain). That behaviour was creating issues when there was aliases configured with duplicates and so on, so we chosen to remove it.
Thanks for the quick response, and for clarifying that the plugin does not work the same as vagrant-hostsupdater.
You suggest that I should be able to use only one alias for the hosts file to be updated, but in my testing outlined In example 2 above, if you define only 1 alias the hosts file is not updated.
Presumably this has something to do with the condition found in this piece of code: https://github.com/goodhosts/vagrant/blob/9994ba1f52eb9b21459db4f96fe78fa02813ee9d/lib/vagrant-goodhosts/GoodHosts.rb#L196-L206
if hostnames[ip_address].count() > 1
implies that you'd need at least two entries for it to start parsing the list to populate the return data in hostnames_by_ips.
I suspect that this might also apply to condition at https://github.com/goodhosts/vagrant/blob/9994ba1f52eb9b21459db4f96fe78fa02813ee9d/lib/vagrant-goodhosts/GoodHosts.rb#L187
You are right code never lies. Should support at least 1 alias, I will update the code.
Software Versions
Host OS : Ubuntu 21.04 goodhosts : 1.0.7 vagrant : 2.2.16 vagrant-goodhosts : 1.0.15 virtualbox: 6.1.22
Problem
When I run
vagrant up
with the vagrant-goodhosts plugin installed I was expecting a hosts entry to be added for thevm.hostname
similar to how the vagrant-hostsupdater plugin worked. On further investigation I've found that in order to get the hosts file to update I need to define at least 2 aliases. I've put together a very basic Vagrantfile using the centos/7 box found at Vagrant Cloud.Example 1 - No Aliases Defined
The following results in no host entries being added when running
vagrant up
:Output:
Expected result
The hosts file contains an entry for
goodhosts.local
.Actual result
The hosts file contains no entry for
goodhosts.local
.It should be noted that there was an assumption on my part that this plugin would work in a similar way to the now defunct vagrant-hostsupdater plugin - can you clarify what the behaviour should be in this situation?
Example 2 - One Alias Defined
The following results in no host entries being added when running
vagrant up
:Output:
Expected result
The hosts file contains entries for:
goodhosts.local
goodhosts1.local
Actual result
The hosts file contains no entry for
goodhosts.local
orgoodhosts1.local
.Example 3 - Two Aliases Defined
The following results in two host entries being added for the aliases only when running
vagrant up
:Output:
Expected result
The hosts file contains entries for:
goodhosts.local
goodhosts1.local
goodhosts2.local
Actual result
The hosts file contains entries for:
goodhosts1.local
goodhosts2.local