vagrant-hosts 2.8.3 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG +19 -0
- data/Gemfile +1 -1
- data/README.markdown +3 -0
- data/lib/vagrant-hosts/cap/sync_hosts/base.rb +31 -7
- data/lib/vagrant-hosts/cap/sync_hosts/posix.rb +9 -12
- data/lib/vagrant-hosts/cap/sync_hosts/windows.rb +45 -13
- data/lib/vagrant-hosts/config.rb +11 -0
- data/lib/vagrant-hosts/config_builder/1_x.rb +2 -0
- data/lib/vagrant-hosts/version.rb +1 -1
- data/vagrant-hosts.gemspec +0 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 322a1b0f577132bf7a26d7e6cf30dbbd4b534cae
|
4
|
+
data.tar.gz: 808c7e2296002dcacd7986f3a026fca00e726175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bc7ab2fd9c7531111315349d6630bb9fbc913f199b8fe52f3aa6e1e508da0b53156e25e9a86d5ed006cd7bb616e20a9093d5cb28d987a5cb11673d8c8bd09d2
|
7
|
+
data.tar.gz: 160746015fcf52be6d95f6334fbbe35d6ce1ce3ae70bc70ab5e34b9222c64a09e221bed3165b1064991c9392caae7ed084eeae4f17c5c5975eebde6a04c557c7
|
data/.travis.yml
CHANGED
@@ -20,8 +20,6 @@ env:
|
|
20
20
|
|
21
21
|
matrix:
|
22
22
|
include:
|
23
|
-
- rvm: 2.0.0
|
24
|
-
env: TEST_VAGRANT_VERSION=v1.7.4 BUNDLER_VERSION=1.10.5
|
25
23
|
- rvm: 2.2.5
|
26
24
|
env: TEST_VAGRANT_VERSION=v1.8.7 BUNDLER_VERSION=1.12.5
|
27
25
|
- rvm: 2.3.4
|
@@ -29,6 +27,8 @@ matrix:
|
|
29
27
|
- rvm: 2.4.4
|
30
28
|
env: TEST_VAGRANT_VERSION=v2.0.4 BUNDLER_VERSION=1.16.1
|
31
29
|
- rvm: 2.4.4
|
32
|
-
env: TEST_VAGRANT_VERSION=v2.1.
|
30
|
+
env: TEST_VAGRANT_VERSION=v2.1.5 BUNDLER_VERSION=1.16.1
|
31
|
+
- rvm: 2.4.4
|
32
|
+
env: TEST_VAGRANT_VERSION=v2.2.2 BUNDLER_VERSION=1.16.1
|
33
33
|
- rvm: 2.4.4
|
34
34
|
env: TEST_VAGRANT_VERSION=HEAD BUNDLER_VERSION=1.16.1
|
data/CHANGELOG
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
2.9.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
2019-01-03
|
8
|
+
|
9
|
+
This is a backwards compatible feature and bugfix release.
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
* New `change_hostname` config setting that controls whether the provisioner
|
14
|
+
will attempt to set the hostname of the VM.
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
* Hostnames can now be removed from Windows VMs.
|
19
|
+
|
20
|
+
* Provisioning hostnames on Windows VMs will no longer fail when a large
|
21
|
+
number of names is added.
|
22
|
+
|
4
23
|
2.8.2
|
5
24
|
-----
|
6
25
|
|
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
require 'rubygems/version'
|
3
3
|
|
4
|
-
vagrant_branch = ENV['TEST_VAGRANT_VERSION'] || 'v2.
|
4
|
+
vagrant_branch = ENV['TEST_VAGRANT_VERSION'] || 'v2.2.2'
|
5
5
|
vagrant_version = nil
|
6
6
|
|
7
7
|
# Wrapping gemspec in the :plugins group causes Vagrant 1.5 and newer to
|
data/README.markdown
CHANGED
@@ -38,6 +38,9 @@ behaviors of each provisioner instance.
|
|
38
38
|
* `add_localhost_hostnames`
|
39
39
|
* Description: A boolean which controls whether the hostname of the machine is added as an alias for `127.0.1.1`
|
40
40
|
* Default: `true`
|
41
|
+
* `change_hostname`
|
42
|
+
* Description: A boolean which controls whether the hostname of the machine will be set during provisioning.
|
43
|
+
* Default: `true`
|
41
44
|
* `sync_hosts`
|
42
45
|
* Description: A boolean which controls whether running the hosts provisioner causes an update on all other running machines.
|
43
46
|
This also happens during machine destruction.
|
@@ -1,7 +1,10 @@
|
|
1
|
-
|
2
|
-
class VagrantHosts::Cap::SyncHosts::Base
|
1
|
+
require 'vagrant-hosts/addresses'
|
3
2
|
|
4
|
-
|
3
|
+
# Abstract guest capability for syncing host resources
|
4
|
+
#
|
5
|
+
# @abstract
|
6
|
+
# @since 2.0.0
|
7
|
+
class VagrantHosts::Cap::SyncHosts::Base
|
5
8
|
include VagrantHosts::Addresses
|
6
9
|
|
7
10
|
def self.sync_hosts(machine, config)
|
@@ -20,15 +23,37 @@ class VagrantHosts::Cap::SyncHosts::Base
|
|
20
23
|
# FIXME: Write tests for this behavior.
|
21
24
|
# TODO: Move this behavior into a config block on the hosts provisioner
|
22
25
|
# so that this capability can remain focused on updating /etc/hosts.
|
23
|
-
|
24
|
-
|
26
|
+
if @config.change_hostname
|
27
|
+
hostname = @machine.config.vm.hostname || @machine.name.to_s
|
28
|
+
change_host_name(hostname)
|
29
|
+
end
|
25
30
|
|
26
|
-
# call to method not implemented by abstract base class
|
27
31
|
update_hosts
|
28
32
|
end
|
29
33
|
|
30
34
|
private
|
31
35
|
|
36
|
+
# Upload /etc/hosts content to a temporary file on the guest
|
37
|
+
def upload_temphosts(hosts_content, dest_path = '/tmp/vagrant-hosts.txt')
|
38
|
+
temp_file = nil
|
39
|
+
|
40
|
+
temp_file = Tempfile.new('vagrant-hosts')
|
41
|
+
temp_file.binmode # Don't convert line endings.
|
42
|
+
|
43
|
+
temp_file.write(hosts_content)
|
44
|
+
temp_file.flush
|
45
|
+
@machine.communicate.upload(temp_file.path, dest_path)
|
46
|
+
ensure
|
47
|
+
temp_file.close unless temp_file.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
# Update the hosts file on a machine
|
51
|
+
#
|
52
|
+
# Subclasses should implement this method with OS-specific logic.
|
53
|
+
def update_hosts
|
54
|
+
raise NotImplementedError
|
55
|
+
end
|
56
|
+
|
32
57
|
# @param name [String] The new hostname to apply on the guest
|
33
58
|
def change_host_name(name)
|
34
59
|
case Vagrant::VERSION
|
@@ -38,5 +63,4 @@ class VagrantHosts::Cap::SyncHosts::Base
|
|
38
63
|
@machine.guest.capability(:change_host_name, name)
|
39
64
|
end
|
40
65
|
end
|
41
|
-
|
42
66
|
end
|
@@ -1,20 +1,15 @@
|
|
1
|
-
# Provide a base class for syncing hosts entries on POSIX systems.
|
2
|
-
|
3
1
|
require 'tempfile'
|
4
2
|
|
3
|
+
# Guest capability for syncing /etc/hosts on POSIX systems
|
4
|
+
#
|
5
|
+
# @since 2.0.0
|
5
6
|
class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base
|
6
7
|
|
7
8
|
private
|
8
9
|
|
9
|
-
def upload_tmphosts
|
10
|
-
cache = Tempfile.new('tmp-hosts')
|
11
|
-
cache.write(format_hosts)
|
12
|
-
cache.flush
|
13
|
-
@machine.communicate.upload(cache.path, '/tmp/hosts')
|
14
|
-
end
|
15
|
-
|
16
10
|
def update_hosts
|
17
|
-
|
11
|
+
hosts_content = format_hosts
|
12
|
+
upload_temphosts(hosts_content, '/tmp/vagrant-hosts.txt')
|
18
13
|
|
19
14
|
# Switch to PTY mode as this provider may execute across multiple machines
|
20
15
|
# which may not have requiretty set to false (i.e. because they're still
|
@@ -24,7 +19,10 @@ class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base
|
|
24
19
|
old_pty_setting = @machine.config.ssh.pty
|
25
20
|
@machine.config.ssh.pty = true
|
26
21
|
|
27
|
-
|
22
|
+
# NOTE: cat is used here instead of mv to work around issues with
|
23
|
+
# Docker filesystem layers not allowing the creation of a
|
24
|
+
# new file.
|
25
|
+
@machine.communicate.sudo('cat /tmp/vagrant-hosts.txt > /etc/hosts')
|
28
26
|
ensure
|
29
27
|
@machine.config.ssh.pty = old_pty_setting
|
30
28
|
end
|
@@ -37,5 +35,4 @@ class VagrantHosts::Cap::SyncHosts::POSIX < VagrantHosts::Cap::SyncHosts::Base
|
|
37
35
|
str << "#{address} #{aliases.join(' ')}\n"
|
38
36
|
end
|
39
37
|
end
|
40
|
-
|
41
38
|
end
|
@@ -1,22 +1,39 @@
|
|
1
|
-
#
|
1
|
+
# Guest capability for updating System32/drivers/etc/hosts on Windows
|
2
|
+
#
|
3
|
+
# @see https://docs.microsoft.com/en-us/previous-versions//bb727005(v=technet.10)#EDAA
|
4
|
+
# Microsoft docs on hostname resolution.
|
5
|
+
# @since 2.0.0
|
2
6
|
class VagrantHosts::Cap::SyncHosts::Windows < VagrantHosts::Cap::SyncHosts::Base
|
3
7
|
|
8
|
+
private
|
9
|
+
|
4
10
|
def update_hosts
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
hosts_content = format_hosts
|
12
|
+
temp_file = [get_tempdir, 'vagrant-hosts.txt'].join('/')
|
13
|
+
upload_temphosts(hosts_content, temp_file)
|
14
|
+
|
15
|
+
@machine.communicate.sudo(<<-EOS)
|
16
|
+
Copy-Item `
|
17
|
+
-Path "#{temp_file}" `
|
18
|
+
-Destination "${Env:WINDIR}/System32/drivers/etc/hosts"
|
19
|
+
EOS
|
20
|
+
end
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
22
|
+
# Return the path of the Windows temporary directory
|
23
|
+
def get_tempdir
|
24
|
+
sudo('Write-Host -Object $Env:TEMP')[:stdout].chomp.gsub("\\", '/')
|
25
|
+
end
|
15
26
|
|
16
|
-
|
17
|
-
|
27
|
+
def format_hosts
|
28
|
+
all_hosts(@config).inject('') do |str, (address, aliases)|
|
29
|
+
# Unlike UNIXy systems, Windows limits the number of host aliases
|
30
|
+
# that can appear on a line to 9.
|
31
|
+
aliases.each_slice(9) do |slice|
|
32
|
+
str << "#{address} #{slice.join(' ')}\r\n"
|
33
|
+
end
|
18
34
|
|
19
|
-
|
35
|
+
str
|
36
|
+
end
|
20
37
|
end
|
21
38
|
|
22
39
|
# Windows needs a modification of the base method because Windows guest names
|
@@ -81,4 +98,19 @@ if ($success -eq $True) {exit 0} else {exit 1}
|
|
81
98
|
@machine.communicate.sudo(powershell)
|
82
99
|
end
|
83
100
|
|
101
|
+
# FIXME: de-duplicate with the facts implementation.
|
102
|
+
def sudo(cmd)
|
103
|
+
stdout = ''
|
104
|
+
stderr = ''
|
105
|
+
|
106
|
+
retval = @machine.communicate.sudo(cmd) do |type, data|
|
107
|
+
if type == :stderr
|
108
|
+
stderr << data
|
109
|
+
else
|
110
|
+
stdout << data
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
{:stdout => stdout, :stderr => stderr, :retval => retval}
|
115
|
+
end
|
84
116
|
end
|
data/lib/vagrant-hosts/config.rb
CHANGED
@@ -41,6 +41,15 @@ module VagrantHosts
|
|
41
41
|
# @since 2.7.0
|
42
42
|
attr_accessor :imports
|
43
43
|
|
44
|
+
# @!attribute [rw] change_hostname
|
45
|
+
# @return [TrueClass, FalseClass] When set to true, running the hosts
|
46
|
+
# provisioner on this VM will change the hostname of the machine to be
|
47
|
+
# the hostname configured or the name of the machine.
|
48
|
+
# Defaults to 'true'.
|
49
|
+
#
|
50
|
+
# @since 2.9.0
|
51
|
+
attr_accessor :change_hostname
|
52
|
+
|
44
53
|
def initialize
|
45
54
|
@hosts = []
|
46
55
|
@exports = {}
|
@@ -48,6 +57,7 @@ module VagrantHosts
|
|
48
57
|
@autoconfigure = UNSET_VALUE
|
49
58
|
@add_localhost_hostnames = UNSET_VALUE
|
50
59
|
@sync_hosts = UNSET_VALUE
|
60
|
+
@change_hostname = UNSET_VALUE
|
51
61
|
end
|
52
62
|
|
53
63
|
# Register a host for entry
|
@@ -81,6 +91,7 @@ module VagrantHosts
|
|
81
91
|
end
|
82
92
|
|
83
93
|
@sync_hosts = false if @sync_hosts == UNSET_VALUE
|
94
|
+
@change_hostname = true if @change_hostname == UNSET_VALUE
|
84
95
|
end
|
85
96
|
|
86
97
|
# @param other [VagrantHosts::Config]
|
data/vagrant-hosts.gemspec
CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.email = ['adrien@somethingsinistral.net', 'source@sharpsteen.net']
|
17
17
|
gem.homepage = 'https://github.com/oscar-stack/vagrant-hosts'
|
18
18
|
|
19
|
-
gem.has_rdoc = true
|
20
19
|
gem.license = 'Apache 2.0'
|
21
20
|
|
22
21
|
gem.files = %x{git ls-files -z}.split("\0")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-hosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Thebo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -39,8 +39,7 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 2.14.0
|
42
|
-
description:
|
43
|
-
Manage static DNS entries and configuration for Vagrant guests.
|
42
|
+
description: " Manage static DNS entries and configuration for Vagrant guests.\n"
|
44
43
|
email:
|
45
44
|
- adrien@somethingsinistral.net
|
46
45
|
- source@sharpsteen.net
|
@@ -105,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
104
|
version: '0'
|
106
105
|
requirements: []
|
107
106
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.6.
|
107
|
+
rubygems_version: 2.6.14.1
|
109
108
|
signing_key:
|
110
109
|
specification_version: 4
|
111
110
|
summary: Manage static DNS on vagrant guests
|