Change config option to allow_hosts_modification
This commit is contained in:
parent
ff0aea4493
commit
b02a78c661
@ -17,12 +17,12 @@ module Vagrant
|
||||
@app.call(env)
|
||||
|
||||
hostname = env[:machine].config.vm.hostname
|
||||
disable_hosts_modification = env[:machine].config.vm.disable_hosts_modification
|
||||
if !hostname.nil? && !disable_hosts_modification
|
||||
allow_hosts_modification = env[:machine].config.vm.allow_hosts_modification
|
||||
if !hostname.nil? && allow_hosts_modification
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.hostname.setting")
|
||||
env[:machine].guest.capability(:change_host_name, hostname)
|
||||
else
|
||||
@logger.info("`disable_hosts_modification` set to true. Hosts modification has been disabled, skiping changing hostname.")
|
||||
@logger.info("`allow_hosts_modification` set to false. Hosts modification has been disabled, skiping changing hostname.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -24,6 +24,7 @@ module VagrantPlugins
|
||||
|
||||
attr_accessor :allowed_synced_folder_types
|
||||
attr_accessor :allow_fstab_modification
|
||||
attr_accessor :allow_hosts_modification
|
||||
attr_accessor :base_mac
|
||||
attr_accessor :base_address
|
||||
attr_accessor :boot_timeout
|
||||
@ -42,7 +43,6 @@ module VagrantPlugins
|
||||
attr_accessor :box_download_location_trusted
|
||||
attr_accessor :box_download_options
|
||||
attr_accessor :communicator
|
||||
attr_accessor :disable_hosts_modification
|
||||
attr_accessor :graceful_halt_timeout
|
||||
attr_accessor :guest
|
||||
attr_accessor :hostname
|
||||
@ -78,7 +78,7 @@ module VagrantPlugins
|
||||
@box_extra_download_options = UNSET_VALUE
|
||||
@box_url = UNSET_VALUE
|
||||
@box_version = UNSET_VALUE
|
||||
@disable_hosts_modification = UNSET_VALUE
|
||||
@allow_hosts_modification = UNSET_VALUE
|
||||
@clone = UNSET_VALUE
|
||||
@communicator = UNSET_VALUE
|
||||
@graceful_halt_timeout = UNSET_VALUE
|
||||
@ -529,7 +529,7 @@ module VagrantPlugins
|
||||
@box_version = nil if @box_version == UNSET_VALUE
|
||||
@box_download_options = {} if @box_download_options == UNSET_VALUE
|
||||
@box_extra_download_options = Vagrant::Util::MapCommandOptions.map_to_command_options(@box_download_options)
|
||||
@disable_hosts_modification = false if @disable_hosts_modification == UNSET_VALUE
|
||||
@allow_hosts_modification = true if @allow_hosts_modification == UNSET_VALUE
|
||||
@clone = nil if @clone == UNSET_VALUE
|
||||
@communicator = nil if @communicator == UNSET_VALUE
|
||||
@graceful_halt_timeout = 60 if @graceful_halt_timeout == UNSET_VALUE
|
||||
@ -997,9 +997,12 @@ module VagrantPlugins
|
||||
if ![TrueClass, FalseClass].include?(@allow_fstab_modification.class)
|
||||
errors["vm"] << I18n.t("vagrant.config.vm.config_type",
|
||||
option: "allow_fstab_modification", given: @allow_fstab_modification.class, required: "Boolean"
|
||||
if ![TrueClass, FalseClass].include?(@disable_hosts_modification.class)
|
||||
errors["vm"] << I18n.t("vagrant.config.vm.disable_host_modification_type",
|
||||
given: @disable_hosts_modification.class
|
||||
)
|
||||
end
|
||||
|
||||
if ![TrueClass, FalseClass].include?(@allow_hosts_modification.class)
|
||||
errors["vm"] << I18n.t("vagrant.config.vm.config_type",
|
||||
option: "allow_hosts_modification", given: @allow_hosts_modification.class, required: "Boolean"
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@ -1941,8 +1941,6 @@ en:
|
||||
Checksum type specified but "box_download_checksum" is blank
|
||||
box_download_checksum_notblank: |-
|
||||
Checksum specified but must also specify "box_download_checksum_type"
|
||||
disable_host_modification_type: |-
|
||||
Expected configuration `disable_hosts_modification` to be type Bool, got %{given}
|
||||
box_missing: "A box must be specified."
|
||||
box_download_options_type: |-
|
||||
Found "box_download_options" specified as type '%{type}', should be a Hash
|
||||
|
||||
@ -50,15 +50,15 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||
end
|
||||
|
||||
it "validates disables_host_modification option" do
|
||||
subject.disable_hosts_modification = true
|
||||
subject.allow_hosts_modification = true
|
||||
subject.finalize!
|
||||
assert_valid
|
||||
|
||||
subject.disable_hosts_modification = false
|
||||
subject.allow_hosts_modification = false
|
||||
subject.finalize!
|
||||
assert_valid
|
||||
|
||||
subject.disable_hosts_modification = "truthy"
|
||||
subject.allow_hosts_modification = "truthy"
|
||||
subject.finalize!
|
||||
assert_invalid
|
||||
end
|
||||
|
||||
@ -15,13 +15,13 @@ describe Vagrant::Action::Builtin::SetHostname do
|
||||
end
|
||||
|
||||
it "should change hostname if hosts modification enabled" do
|
||||
allow(machine).to receive_message_chain(:config, :vm, :disable_hosts_modification).and_return(false)
|
||||
allow(machine).to receive_message_chain(:config, :vm, :allow_hosts_modification).and_return(true)
|
||||
expect(machine).to receive(:guest)
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
it "should not change hostname if hosts modification disabled" do
|
||||
allow(machine).to receive_message_chain(:config, :vm, :disable_hosts_modification).and_return(true)
|
||||
allow(machine).to receive_message_chain(:config, :vm, :allow_hosts_modification).and_return(false)
|
||||
expect(machine).not_to receive(:guest)
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
@ -21,6 +21,9 @@ machine that Vagrant manages.
|
||||
by Vagrant. Note, this may mean that folders will not be automatically mounted
|
||||
on machine reboot. Defaults to true.
|
||||
|
||||
- `config.vm.allow_hosts_modification` (boolean) - If false, will prevent Vagrant
|
||||
from writing to `/etc/hosts`. Defaults to true.
|
||||
|
||||
- `config.vm.base_mac` (string) - The MAC address to be assigned to the default
|
||||
NAT interface on the guest. _Support for this option is provider dependent._
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user