2013-03-20 14:41:21 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Ansible
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
|
|
|
attr_accessor :playbook
|
|
|
|
attr_accessor :extra_vars
|
2013-08-09 18:06:02 +00:00
|
|
|
attr_accessor :inventory_path
|
2013-03-20 14:41:21 +00:00
|
|
|
attr_accessor :ask_sudo_pass
|
2014-03-27 07:56:55 +00:00
|
|
|
attr_accessor :ask_vault_pass
|
|
|
|
attr_accessor :vault_password_file
|
2013-03-20 14:41:21 +00:00
|
|
|
attr_accessor :limit
|
|
|
|
attr_accessor :sudo
|
|
|
|
attr_accessor :sudo_user
|
|
|
|
attr_accessor :verbose
|
2013-05-06 19:17:45 +00:00
|
|
|
attr_accessor :tags
|
2013-08-12 07:41:18 +00:00
|
|
|
attr_accessor :skip_tags
|
2013-05-14 03:25:28 +00:00
|
|
|
attr_accessor :start_at_task
|
2013-12-09 07:01:01 +00:00
|
|
|
attr_accessor :groups
|
2013-09-14 02:48:12 +00:00
|
|
|
attr_accessor :host_key_checking
|
2013-03-20 14:41:21 +00:00
|
|
|
|
2014-03-09 21:47:24 +00:00
|
|
|
# Joker attribute, used to pass unsupported arguments to ansible-playbook anyway
|
2013-05-06 20:28:20 +00:00
|
|
|
attr_accessor :raw_arguments
|
2014-03-09 21:47:24 +00:00
|
|
|
# Joker attribute, used to set additional SSH parameters for ansible-playbook anyway
|
|
|
|
attr_accessor :raw_ssh_args
|
2013-03-20 14:41:21 +00:00
|
|
|
|
|
|
|
def initialize
|
2014-03-27 07:56:55 +00:00
|
|
|
@playbook = UNSET_VALUE
|
|
|
|
@extra_vars = UNSET_VALUE
|
|
|
|
@inventory_path = UNSET_VALUE
|
|
|
|
@ask_sudo_pass = UNSET_VALUE
|
|
|
|
@ask_vault_pass = UNSET_VALUE
|
|
|
|
@vault_password_file = UNSET_VALUE
|
|
|
|
@limit = UNSET_VALUE
|
|
|
|
@sudo = UNSET_VALUE
|
|
|
|
@sudo_user = UNSET_VALUE
|
|
|
|
@verbose = UNSET_VALUE
|
|
|
|
@tags = UNSET_VALUE
|
|
|
|
@skip_tags = UNSET_VALUE
|
|
|
|
@start_at_task = UNSET_VALUE
|
|
|
|
@groups = UNSET_VALUE
|
|
|
|
@host_key_checking = UNSET_VALUE
|
|
|
|
@raw_arguments = UNSET_VALUE
|
|
|
|
@raw_ssh_args = UNSET_VALUE
|
2013-03-20 14:41:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2014-03-27 07:56:55 +00:00
|
|
|
@playbook = nil if @playbook == UNSET_VALUE
|
|
|
|
@extra_vars = nil if @extra_vars == UNSET_VALUE
|
|
|
|
@inventory_path = nil if @inventory_path == UNSET_VALUE
|
|
|
|
@ask_sudo_pass = false unless @ask_sudo_pass == true
|
2014-04-14 03:24:57 +00:00
|
|
|
@ask_vault_pass = false unless @ask_vault_pass == true
|
2014-03-27 07:56:55 +00:00
|
|
|
@vault_password_file = nil if @vault_password_file == UNSET_VALUE
|
|
|
|
@limit = nil if @limit == UNSET_VALUE
|
|
|
|
@sudo = false unless @sudo == true
|
|
|
|
@sudo_user = nil if @sudo_user == UNSET_VALUE
|
|
|
|
@verbose = nil if @verbose == UNSET_VALUE
|
|
|
|
@tags = nil if @tags == UNSET_VALUE
|
|
|
|
@skip_tags = nil if @skip_tags == UNSET_VALUE
|
|
|
|
@start_at_task = nil if @start_at_task == UNSET_VALUE
|
|
|
|
@groups = {} if @groups == UNSET_VALUE
|
|
|
|
@host_key_checking = false unless @host_key_checking == true
|
|
|
|
@raw_arguments = nil if @raw_arguments == UNSET_VALUE
|
|
|
|
@raw_ssh_args = nil if @raw_ssh_args == UNSET_VALUE
|
2013-03-20 14:41:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate(machine)
|
2013-09-04 23:56:45 +00:00
|
|
|
errors = _detected_errors
|
2013-04-05 16:43:56 +00:00
|
|
|
|
2013-04-04 06:07:07 +00:00
|
|
|
# Validate that a playbook path was provided
|
2013-03-20 14:41:21 +00:00
|
|
|
if !playbook
|
|
|
|
errors << I18n.t("vagrant.provisioners.ansible.no_playbook")
|
|
|
|
end
|
2013-04-05 16:43:56 +00:00
|
|
|
|
2013-04-04 06:07:07 +00:00
|
|
|
# Validate the existence of said playbook on the host
|
|
|
|
if playbook
|
|
|
|
expanded_path = Pathname.new(playbook).expand_path(machine.env.root_path)
|
|
|
|
if !expanded_path.file?
|
|
|
|
errors << I18n.t("vagrant.provisioners.ansible.playbook_path_invalid",
|
|
|
|
:path => expanded_path)
|
|
|
|
end
|
|
|
|
end
|
2013-04-05 16:43:56 +00:00
|
|
|
|
2013-11-25 05:29:04 +00:00
|
|
|
# Validate that extra_vars is either a hash, or a path to an
|
|
|
|
# existing file
|
2013-04-05 16:40:32 +00:00
|
|
|
if extra_vars
|
2013-11-25 05:29:04 +00:00
|
|
|
extra_vars_is_valid = extra_vars.kind_of?(Hash) || extra_vars.kind_of?(String)
|
2013-10-11 22:29:39 +00:00
|
|
|
if extra_vars.kind_of?(String)
|
2013-11-25 05:29:04 +00:00
|
|
|
# Accept the usage of '@' prefix in Vagrantfile (e.g. '@vars.yml'
|
|
|
|
# and 'vars.yml' are both supported)
|
|
|
|
match_data = /^@?(.+)$/.match(extra_vars)
|
|
|
|
extra_vars_path = match_data[1].to_s
|
2013-10-11 22:29:39 +00:00
|
|
|
expanded_path = Pathname.new(extra_vars_path).expand_path(machine.env.root_path)
|
|
|
|
extra_vars_is_valid = expanded_path.exist?
|
|
|
|
if extra_vars_is_valid
|
|
|
|
@extra_vars = '@' + extra_vars_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if !extra_vars_is_valid
|
|
|
|
errors << I18n.t("vagrant.provisioners.ansible.extra_vars_invalid",
|
|
|
|
:type => extra_vars.class.to_s,
|
|
|
|
:value => extra_vars.to_s
|
|
|
|
)
|
2013-04-05 16:40:32 +00:00
|
|
|
end
|
|
|
|
end
|
2013-04-05 16:43:56 +00:00
|
|
|
|
2013-08-09 18:06:02 +00:00
|
|
|
# Validate the existence of the inventory_path, if specified
|
|
|
|
if inventory_path
|
|
|
|
expanded_path = Pathname.new(inventory_path).expand_path(machine.env.root_path)
|
2013-08-09 18:04:35 +00:00
|
|
|
if !expanded_path.exist?
|
2013-08-09 18:06:02 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.ansible.inventory_path_invalid",
|
2013-04-04 06:07:07 +00:00
|
|
|
:path => expanded_path)
|
|
|
|
end
|
|
|
|
end
|
2013-03-20 14:41:21 +00:00
|
|
|
|
2014-04-14 03:24:57 +00:00
|
|
|
# Validate the existence of the vault_password_file, if specified
|
|
|
|
if vault_password_file
|
|
|
|
expanded_path = Pathname.new(vault_password_file).expand_path(machine.env.root_path)
|
|
|
|
if !expanded_path.exist?
|
|
|
|
errors << I18n.t("vagrant.provisioners.ansible.vault_password_file_invalid",
|
|
|
|
:path => expanded_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-20 14:41:21 +00:00
|
|
|
{ "ansible provisioner" => errors }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-04-04 07:24:14 +00:00
|
|
|
end
|