vagrant-hostmanager icon indicating copy to clipboard operation
vagrant-hostmanager copied to clipboard

Deactivate host

Open alainux opened this issue 10 years ago • 8 comments

Hi guys,

I'd like an easy way to deactivate the host. I currently host a vagrant machine that points to myhost.com, and the stage server is in myhost.com as well.

Upon deployment, I have to vim /etc/hosts/and add a # to the vagrant entry created by hostmanager.

Is there an easy way to do this using vagrant hostmanager that could work as a workaround?

alainux avatar May 01 '14 16:05 alainux

Which /etc/hosts file are you trying to exclude the machine from? The one on the host machine, or on other guest machines in the same vagrant environment?

pbitty avatar May 02 '14 13:05 pbitty

@pbitty The ones on the host. My current solution:

#!/bin/bash
sudo sed -e '/machinehostname/s/^/#/' /etc/hosts

But I think this really should be on hostmanager as an option.

alainux avatar May 02 '14 16:05 alainux

Are you trying to exclude this guest from hostmanager completely, or just from the host's /etc/hosts file?

pbitty avatar May 05 '14 16:05 pbitty

Whoops, it seems I already asked that question. :)

What I am trying to clarify is this:

  1. do you have multiple VMs in the same Vagrantfile that need to see each other?
  2. if yes, you want the myhost.com VM to still appear in /etc/hosts of the other guests, but not /etc/hosts on the host VM, correct?

pbitty avatar May 05 '14 16:05 pbitty

@pbitty I don't have multiple VM's but I can see that being an issue for other folks.

The problem: vagrant destroy and vagrant up both toggle the /etc/hosts entry on the host machine (when configured). When working on a dev->stage environment, I need:

machineip stageurl

on the host's /etc/hosts file to work on development. When pushing to stage it's safe to do

vagrant destroy

which deactivates the entry on the host's /etc/hosts, and I can safely check stageurl on the browser to see the results.

However, vagrant destroy and vagrant up are both slow commands, and If I want to do a quick check on the stage server (just deactivate the /etc/hosts entry and check the browser), there's no command to quickly remove the entry.

As I said, currently I'm manually editing /etc/hosts to comment it out for quick checks, which is not terrible, but following issue #56, where there's a suggestion to make vagrant halt remove the entry on the host's hosts file, I think that a simpler

vagrant hostmanager deactivate

That simply comments out the entry on the host by doing something similar to sudo sed -e '/machinehostname/s/^/#/' /etc/hosts could work nicely.

alainux avatar May 05 '14 16:05 alainux

That's an interesting idea. I agree, I think it would be useful to be able to remove the entries from the host's /etc/hosts file, since it is used by all DNS lookups on your machine.

I think having a command like cleanhost might be more explicit as to what it's doing.

To remove the entries from the current vagrant environment:

vagrant hostmanager cleanhost

To remoove the entries from all vagrant environments:

vagrant hostmanager cleanhost --all

This last one is useful for removing entries for environments that you no longer have around. I've definitely had to do that from time to time.

What do you think?

pbitty avatar May 14 '14 12:05 pbitty

As to your specific use-case, have you considered having a way of dynamically setting the hostname you're pointing to based on environment?

ie:

  • for your dev environment, configure it to point to myhost.dev
  • for your staging environment, configure it to point to myhost.com

I obviously know nothing about your setup, so I'm just throwing the idea out there. :)

pbitty avatar May 14 '14 12:05 pbitty

Bump for this cleanhost feature.

Here is how it's implemented in other plugin: https://github.com/mosaicxm/vagrant-hostmaster#remove-host-entries

arm4b avatar Aug 04 '14 17:08 arm4b