Gilles Cornu a7ee56459b provisioners/ansible(both): fix ansible config files presence checks
With this change, the presence of Ansible configuration files (like
playbook file, inventory path, galaxy role file, etc.) is no longer
performed by the `config` classes, but by the `provisioner` classes
(at the beginning of the provision command).

This change fixes several issues:

- Resolve #6984 as `provision` method are only executed when remote
  (ssh) communication with the guest machine is possible.
- Resolve #6763 in a better way than 4e451c6 initially did.
- Improve the general provisioner speed since the `config` checks are
  actually triggered by many vagrant actions (e.g. `destroy`,...), and
  can also be triggered multiple times during a vagrant run (e.g. on
  callback request made by the machine provider).

Unlike the former `config`-based checks, the provision action won't
collect all the invalid options, but only report the first invalid
option found and abort the execution.

Some unit tests were not implemented yet to save my scarce "open source
contribution time" for other important issues, but they should be done
at last via GH-6633.
2016-06-01 06:40:23 +02:00

55 lines
1.5 KiB
Ruby

require_relative "base"
module VagrantPlugins
module Ansible
module Config
class Host < Base
attr_accessor :ask_sudo_pass
attr_accessor :ask_vault_pass
attr_accessor :force_remote_user
attr_accessor :host_key_checking
attr_accessor :raw_ssh_args
def initialize
super
@ask_sudo_pass = false
@ask_vault_pass = false
@force_remote_user = true
@host_key_checking = false
@raw_ssh_args = UNSET_VALUE
end
def finalize!
super
@ask_sudo_pass = false if @ask_sudo_pass != true
@ask_vault_pass = false if @ask_vault_pass != true
@force_remote_user = true if @force_remote_user != false
@host_key_checking = false if @host_key_checking != true
@raw_ssh_args = nil if @raw_ssh_args == UNSET_VALUE
end
def validate(machine)
super
if raw_ssh_args
if raw_ssh_args.kind_of?(String)
@raw_ssh_args = [raw_ssh_args]
elsif !raw_ssh_args.kind_of?(Array)
@errors << I18n.t(
"vagrant.provisioners.ansible.errors.raw_ssh_args_invalid",
type: raw_ssh_args.class.to_s,
value: raw_ssh_args.to_s)
end
end
{ "ansible remote provisioner" => @errors }
end
end
end
end
end