Git Product home page Git Product logo

vagrant-1's Introduction

Vagrant::Goodhosts

This vagrant plugin adds host file entries to the host pointing to the guest VM, using the GoodHosts cli tool. This plugin is based on vagrant-hostsupdater and aims to be compatible with the same config parameters.

On up, resume and reload commands, it tries to add the hosts if they do not already exist in your hosts file. If it needs to be added, you will be asked for the sudo password to make the necessary edits.

On halt, destroy, and suspend, those entries will be removed again. By setting the config.goodhosts.remove_on_suspend = false, suspend and halt will not remove them.

Installation

vagrant plugin install vagrant-goodhosts

To uninstall :

vagrant plugin uninstall vagrant-goodhosts

To update the plugin:

vagrant plugin update vagrant-goodhosts

Usage

You currently only need the hostname and a :private_network network with a fixed IP address.

config.vm.network :private_network, ip: "192.168.3.10"
config.vm.hostname = "www.testing.de" # This is not used by the plugin
config.goodhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]

This IP address and the hostname will be used for the entry in the /etc/hosts file.

vagrant-hostsupdater conflicts

The original plugin has the issue of be executed in any vagrant environment, also that is not using and will add a rule in the hosts file that is not generated by this one. To avoid issues is better to remove that plugin and in case update accordingly the Vagrantfile if use it. Require just a change of the reference of the plugin name as the example above.

Multiple private network adapters

If you have multiple network adapters i.e.:

config.vm.network :private_network, ip: "10.0.0.1"
config.vm.network :private_network, ip: "10.0.0.2"

You can specify which hostnames are bound to which IP by passing a hash mapping the IP of the network to an array of hostnames to create, e.g.:

config.goodhosts.aliases = {
    '10.0.0.1' => ['foo.com', 'bar.com'],
    '10.0.0.2' => ['baz.com', 'bat.com']
}

This will produce /etc/hosts entries like so:

10.0.0.1 foo.com
10.0.0.1 bar.com
10.0.0.2 baz.com
10.0.0.2 bat.com

Keeping Host Entries After Suspend/Halt

To keep your /etc/hosts file unchanged simply add the line below to your VagrantFile:

config.goodhosts.remove_on_suspend = false

This disables vagrant-goodhosts from running on suspend and halt.

Disable file hosts clean

If you want /etc/hosts file cleaned add in your VagrantFile:

config.goodhosts.disable_clean = false

This enable vagrant-goodhosts from running the clean command in every call.

Suppressing prompts for elevating privileges

These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file. If you understand the risks that go with supressing them, here's how to do it.

Linux/OS X: Passwordless sudo

To allow vagrant to automatically update the hosts file without asking for a sudo password, add one of the following snippets to a new sudoers file include, i.e. sudo visudo -f /etc/sudoers.d/vagrant_goodhosts. The command path is printed when there are errors with sudo.

For Ubuntu and most Linux environments:

%sudo ALL=(root) NOPASSWD: [the-path]

For MacOS:

%admin ALL=(root) NOPASSWD: [the-path]

Replace in both %sudo/%admin with the username it if it is not working for you.

Windows: UAC Prompt

You can use cacls or icacls to grant your user account permanent write permission to the system's hosts file. You have to open an elevated command prompt; hold โ– Win and press X, then choose "Command Prompt (Admin)"

cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W

Installing The Development Version

If you would like to install vagrant-goodhosts to make contributions or changes, run the following commands::

git clone https://github.com/goodhosts/vagrant vagrant-goodhosts
cd vagrant-goodhosts
./package.sh
vagrant plugin install vagrant-goodhosts-*.gem

vagrant-1's People

Contributors

agiledivider avatar aki2o avatar br0ken- avatar cgsmith avatar danepowell avatar dvzubarev avatar fabacab avatar jugglinmike avatar kogent avatar luanntvn avatar markjaquith avatar markus-altran avatar maximerety avatar milest avatar msaggiorato avatar mte90 avatar phersh avatar radeksimko avatar rmarchei avatar rrader avatar serverbrain avatar suin avatar svelix avatar tkdb avatar tobych avatar tomjn avatar vincentmac avatar weynhamz avatar ypcs avatar zanea avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.