Before this change, the detection of a non-existing path on the guest machine was considered as an error and lead to interrupt the current vagrant action. This was actually a mistake to do so, since the config checks are performed before many other vagrant actions than `provision`. The config.validate phase is also intended to primarily check the options sanity, but it cannot be too strict with the guest state (which can easily get "out of automatic control"). With this change, we still apply these checks (when possible), but only warn about possible configuration problems. This way, the subsequent statements will happen anyway (e.g. ansible commands will be executed, vagrant machine will be destroyed, etc.)
67 lines
2.0 KiB
Ruby
67 lines
2.0 KiB
Ruby
require_relative "base"
|
|
|
|
module VagrantPlugins
|
|
module Ansible
|
|
module Config
|
|
class Guest < Base
|
|
|
|
attr_accessor :provisioning_path
|
|
attr_accessor :tmp_path
|
|
attr_accessor :install
|
|
attr_accessor :version
|
|
|
|
def initialize
|
|
super
|
|
|
|
@install = UNSET_VALUE
|
|
@provisioning_path = UNSET_VALUE
|
|
@tmp_path = UNSET_VALUE
|
|
@version = UNSET_VALUE
|
|
end
|
|
|
|
def finalize!
|
|
super
|
|
|
|
@install = true if @install == UNSET_VALUE
|
|
@provisioning_path = "/vagrant" if provisioning_path == UNSET_VALUE
|
|
@tmp_path = "/tmp/vagrant-ansible" if tmp_path == UNSET_VALUE
|
|
@version = "" if @version == UNSET_VALUE
|
|
end
|
|
|
|
def validate(machine)
|
|
super
|
|
|
|
{ "ansible local provisioner" => @errors }
|
|
end
|
|
|
|
protected
|
|
|
|
def check_path(machine, path, test_args, error_message_key = nil)
|
|
remote_path = Helpers::expand_path_in_unix_style(path, @provisioning_path)
|
|
|
|
if machine.communicate.ready? && !machine.communicate.test("test #{test_args} #{remote_path}")
|
|
if error_message_key
|
|
# only show warnings, as raising an error would abort the request
|
|
# vagrant action (e.g. prevent `destroy` to be executed)
|
|
machine.ui.warn(I18n.t(error_message_key, path: remote_path, system: "guest"))
|
|
end
|
|
return false
|
|
end
|
|
# when the machine is not ready for SSH communication,
|
|
# the check is "optimistically" bypassed.
|
|
true
|
|
end
|
|
|
|
def check_path_is_a_file(machine, path, error_message_key = nil)
|
|
check_path(machine, path, "-f", error_message_key)
|
|
end
|
|
|
|
def check_path_exists(machine, path, error_message_key = nil)
|
|
check_path(machine, path, "-e", error_message_key)
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|