-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync state with hosts file in blocks #52
Conversation
With these changes, the hosts file looks like this after booting up the machines in the test folder:
When all machines are destroyed, the whole block goes away. What do you guys think? |
@smdahlen Are you ok with me merging this? I'm asking because it's a bit of a significant change. |
I'll take a look tomorrow morning and let you know. |
Hi @smdahlen, I am eager to merge this. I've been using it on my own branch it's working well. If you don't have time to test it out, could you tell me if you agree with the concept? This would fix issues where old entries end up left behind in the /etc/hosts (see #58), sometimes blocking new entries that use the same IP. |
@pbitty Sorry, just got around to review. I think the concept is sound and think it is worth merging. After the merge, I'll go ahead and push out a new gem. Probably worth a bump on the minor version. |
@pbitty @smdahlen I have one issue with implementation, I don't like the idea to have in /etc/hosts on cloud machines path to my local Vagrantfile, imagine I'm sharing this with some other colleagues and his git repo is in different place, basically the info line will be changing depending on which user is invoking hostmanager. I wasn't sure why the id is really needed since header and footer should be enough. One problem could be if:
|
@elyast The path to the Vagrantfile is definitely not necessary. I put it there to make it easier to know where the vagrant-hostmanager block came from. This is really only useful in the host machine's The ID is actually necessary, but only on the host machine. If you have multiple vagrant setups on your machine, this allows vagrant-hostmanager to manage the different independent blocks in the hosts file. Maybe what we need is to have slightly different behavior for editing /etc/hosts in the guest and in the host machines. For the guest machine, we'd have no ID or Vagrantfile path, as you suggested. Does that sound like a reasonable solution? I am willing to make that change. Let me know what you think. |
@pbitty Sounds reasonable :) |
@elyast Sorry for the delay, been a busy week. |
Sure do I will let you know |
Hi, I merged your branch to my fork and it works fine. I also looked at the code, and I think it's fine, it's maybe a little bit deep level of invocation, but on the other hand methods are small and clean. Thanks |
Sync state with hosts file in blocks
@elyast Thanks for the test and feedback. I agree the level of invocation is a bit deep, but I'll leave refactoring for when more changes are required. :) |
Pull request #45 added logic to remove destroyed machines from the hosts file. However, it seems that it only works if you have
include_offline = true
.When
include_offline
is false, the machine being destroyed is not returned byget_machines
in hosts_file.rb:63.This got me thinking of how to clean up the hosts file without any knowledge of machines and names that we may have put in there in the past.
I'm thinking about the idea of delineating a block in the hosts file that belongs to a specific vagrant environment. To sync with the hosts file, we would only have to replace the whole block instead of replacing specific lines. This way we always push the current machine state, without needing to know about what to remove.
Something like this:
This would require a way to uniquely identify this block. One way this could be done is to generate a UUID and store it in
env[:local_data_path]
, which is where vagrant keeps state attached to a specificVagrantfile
.@smdahlen @bdcribbs , what do you think of this?