Skip to content
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

Automate adding hosts entries #140

Closed
rmccue opened this issue Aug 28, 2013 · 28 comments
Closed

Automate adding hosts entries #140

rmccue opened this issue Aug 28, 2013 · 28 comments

Comments

@rmccue
Copy link

rmccue commented Aug 28, 2013

Step 7 of The First Vagrant Up says:

Add a record to your local machine's hosts file

This sucks. 👎

On the other hand, vagrant hostsupdater:

This plugin adds an entry to your /etc/hosts file on the host system.

This does not suck. ✨

You can even specify more than one:

config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]

Although interestingly, Vagrant does error if you don't have the plugin installed. ⚠️ (I'm still investigating how to have this not happen; if anyone has any ideas, please let me know.)

Verdict? :shipit:

@simonwheatley
Copy link
Contributor

At first glance, I like something like Vagrant DNS more… so the DNS works on the host machine and the Vagrant.

@rmccue
Copy link
Author

rmccue commented Aug 28, 2013

This is true. I use Puppet personally, which has a host resource that I use instead.

Reasons for hostupdater over Vagrant DNS:

  • No extra configuration required, whereas Vagrant DNS seems to require a TLD
  • Runs a separate DNS server, which may not be desirable
  • OS X only, which is IMO a non-starter (we're working in VMs to get away from system dependency, not add more)

Reasons for Vagrant DNS over hostsupdater:

  • Registers hosts both locally and in the VM
  • Supports subdomains natively

@danielbachhuber
Copy link
Contributor

We're planning to use hostsupdater + a bit of Ruby to populate the array based on the contents of the projects directory.

@jeremyfelt
Copy link
Member

Big +1 for hostsupdater. I think the only barrier with VVV is streamlining the process with which the plugin is installed. We could consider making it a required installation step, but it'd be really slick to quietly skip over it if not available. I'm sure there has to be an if plugin method or Ruby call that can help us.

Also +1 for the Salty way. I'm sure there's a way to read a config file, possibly one that goes hand in hand with #100. If we have to edit Vagrantfile for every host that we add, ugh. :)

@simonwheatley - I've thought about using some kind of internal DNS setup because it is appealing. I think there are too many wildcards for what domains could be setup for testing (I hardly use .dev myself), and DNS can be tough to screw with.

@jeremyfelt
Copy link
Member

There's Bindler, a plugin for managing plugin dependencies. This would be fantastic if it didn't become a dependency of its own. :)

@jeremyfelt
Copy link
Member

Working with this right now and it appears to work. Will have something to test soon.

if defined? VagrantPlugins::HostsUpdater
    config.hostsupdater.aliases = ["hithere.com"]
end

@jeremyfelt
Copy link
Member

The only bummer is that it's kind of ugly after a nice provisioning script and it depending on your machine it most likely requires that you enter a password. Trade off is happiness though, so there's that.

screen shot 2013-08-28 at 9 40 54 am

jeremyfelt added a commit that referenced this issue Aug 28, 2013
If the hostsupdater plugin is installed, we add the domains used by VVV to the local machine's hosts file. If the hostsupdater plugin is not installed, no hosts file changes are made and no errors are thrown.

In the near term we'll want to work on a way to pull these aliases in from some kind of config file that can be maintained locally so that Vagrantfile can be updated with ease.

For now - if you'd like to add more aliases and don't want to worry about merging new commits from the master repo, the best bet may be to maintain a Customfile with an additional config line for `config.hostsupdater.aliases`.

Addresses #140, may likely fix it. I was too lazy to make a pull request, I'm sorry. :)
@jeremyfelt
Copy link
Member

Thanks for the prod, @rmccue, this is lovely. ✨

@jeremyfelt
Copy link
Member

At first glance, I like something like Vagrant DNS more… so the DNS works on the host machine and the Vagrant.

I think we can accomplish this once we have a local config file containing the aliases. It can be parsed via script inside provision.sh and added to the internal hosts file.

@simonwheatley
Copy link
Contributor

At first glance, I like something like Vagrant DNS more… so the DNS works on the host machine and the Vagrant.

I think we can accomplish this once we have a local config file containing the aliases. It can be parsed via script inside provision.sh and added to the internal hosts file.

Sounds great. @danielbachhuber's comment above about populating from some projects folder or similar, sounds interesting and relevant to #100 & #121.

@TheLastCicada
Copy link
Contributor

My concern here is..... do any of these solutions work on Windows?

@jeremyfelt
Copy link
Member

My concern here is..... do any of these solutions work on Windows?

Yup, Vagrant Hostsupdater is cross platform. Definitely need some Windows users to test it though. Working great on OSX so far.

@TheLastCicada
Copy link
Contributor

Excellent - would love to hear from a Windows user who could test this!

@jeremyfelt
Copy link
Member

Ping @westonruter or @ericmann - you guys up for testing this out?

@westonruter
Copy link
Contributor

I am _NOT_ on Windows ❗❗❗

@johnpbloch
Copy link
Contributor

ROFL

@jeremyfelt
Copy link
Member

Woops. :)

How about @rclilly?

@johnpbloch
Copy link
Contributor

Part of me wants to ping Linus on this thread just to see what would happen...

@TheLastCicada
Copy link
Contributor

@ericmann is out of town for the next 2 weeks - he is usually my go-to

@rclilly
Copy link

rclilly commented Aug 28, 2013

@jeremyfelt @TheLastCicada Yes, I am on Windows! I'll look this over and give it a go and report back.

@rclilly
Copy link

rclilly commented Aug 28, 2013

The vagrant-hostupdater gets a "Permission denied" error and creation of the VM fails.

Here are the steps I took and the results:

  1. vagrant plugin install vagrant-hostsupdater = Success!
  2. fresh clone of VVV = Success!
  3. vagrant up = Errors :-(

Relevant excerpt from the bash window:

"Provisioning complete in 2420 seconds
External network connection established, packages up to date.
For further setup instructions, visit http://192.168.50.4
[default] Checking for host entries
[default] adding to (C:/Windows/system32/drivers/etc/hosts) : 192.168.50.4 vvv # VAGRANT: 7a3abd5b27092bd7cf7b008a149ca69e (default) / e0991462-b86f-4d67-afd7-dd224383b70e
[default] adding to (C:/Windows/system32/drivers/etc/hosts) : 192.168.50.4 local.wordpress.dev # VAGRANT: 7a3abd5b27092bd7cf7b008a149ca69e (default) / e0991462-b86f-4d67-afd7-dd224383b70e
[default] adding to (C:/Windows/system32/drivers/etc/hosts) : 192.168.50.4 local.wordpress-trunk.dev # VAGRANT: 7a3abd5b27092bd7cf7b008a149ca69e (default) / e0991462-b86f-4d67-afd7-dd224383b70e
[default] adding to (C:/Windows/system32/drivers/etc/hosts) : 192.168.50.4 src.wordpress-develop.dev # VAGRANT: 7a3abd5b27092bd7cf7b008a149ca69e (default) / e0991462-b86f-4d67-afd7-dd224383b70e
[default] adding to (C:/Windows/system32/drivers/etc/hosts) : 192.168.50.4 build.wordpress-develop.dev # VAGRANT: 7a3abd5b27092bd7cf7b008a149ca69e (default) / e0991462-b86f-4d67-afd7-dd224383b70e
[default] Forcing shutdown of VM...
[default] Destroying VM and associated drives...
E:/Users/Robert-laptop/.vagrant.d/gems/gems/vagrant-hostsupdater-0.0.10/lib/vagrant-hostsupdater/HostsUpdater.rb:77:in `initialize': Permission denied - C:/Windows/system32/drivers/etc/hosts (Errno::EACCES)"

I followed this with vagrant halt and then did another vagrant up and got the same results. It looks like vagrant-hostupdater needs some work to be able to deal with Windows permissions.

An unrelated error which occurred is:
"Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

http://gruntjs.com/getting-started"

@rmccue
Copy link
Author

rmccue commented Aug 28, 2013

I am also a Windows user. :) Since Windows doesn't have sudo or similar, you have to make your hosts file world-writable. Once that's done, it works perfectly.

@rclilly
Copy link

rclilly commented Aug 28, 2013

Update: opened the bash window/command prompt with "Run as Administrator" and did vagrant up. Everything worked fine, both the vagrant-hostsupdater and the installation of Grunt! I verified that 5 new lines were added to my hosts file, all providing a hostname for 192.168.50.4. Yeah!

Maybe we need to update the instructions for Windows users to always make sure the command prompt/bash window is opened with elevated privileges?

@rmccue How does one make the hosts file world-writable in Windows?

@rclilly
Copy link

rclilly commented Aug 28, 2013

Update to the update: Verified that the entries to the hosts file are removed upon vagrant halt.

@rmccue
Copy link
Author

rmccue commented Aug 29, 2013

@rclilly Actually, I didn't make it world-writable, but I gave my user the permissions to edit it without being admin. The easiest way to do it is: Properties -> Security -> Edit -> Add -> [your user] -> Full Control.

Note that when running via Cygwin using PuTTY, you can't run as an administrator, so you need this. For normal users though, running as admin should be fine.

@jeremyfelt
Copy link
Member

Seems like we're good to go here, so I'm going to close this out.

@jeremyfelt
Copy link
Member

A note for handling this in the future... Vagrant 1.3.0 will have Vagrant.has_plugin? available to use.

@lock
Copy link

lock bot commented Feb 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants