vagrant-hostmanager
vagrant-hostmanager copied to clipboard
Deactivate host
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?
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 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.
Are you trying to exclude this guest from hostmanager completely, or just from the host's /etc/hosts file?
Whoops, it seems I already asked that question. :)
What I am trying to clarify is this:
- do you have multiple VMs in the same Vagrantfile that need to see each other?
- 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 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.
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?
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. :)
Bump for this cleanhost
feature.
Here is how it's implemented in other plugin: https://github.com/mosaicxm/vagrant-hostmaster#remove-host-entries