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
|
|
|
|
attr_accessor :inventory_file
|
|
|
|
attr_accessor :ask_sudo_pass
|
|
|
|
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-03-20 14:41:21 +00:00
|
|
|
|
2013-05-06 20:28:20 +00:00
|
|
|
# Joker attribute, used to pass unsupported arguments to ansible anyway
|
|
|
|
attr_accessor :raw_arguments
|
|
|
|
|
2013-03-20 14:41:21 +00:00
|
|
|
def initialize
|
|
|
|
@playbook = UNSET_VALUE
|
|
|
|
@extra_vars = UNSET_VALUE
|
|
|
|
@inventory_file = UNSET_VALUE
|
|
|
|
@ask_sudo_pass = UNSET_VALUE
|
|
|
|
@limit = UNSET_VALUE
|
|
|
|
@sudo = UNSET_VALUE
|
|
|
|
@sudo_user = UNSET_VALUE
|
|
|
|
@verbose = UNSET_VALUE
|
2013-05-06 19:17:45 +00:00
|
|
|
@tags = UNSET_VALUE
|
2013-05-06 20:28:20 +00:00
|
|
|
@raw_arguments = UNSET_VALUE
|
2013-03-20 14:41:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
|
|
|
@playbook = nil if @playbook == UNSET_VALUE
|
|
|
|
@extra_vars = nil if @extra_vars == UNSET_VALUE
|
|
|
|
@inventory_file = nil if @inventory_file == UNSET_VALUE
|
|
|
|
@ask_sudo_pass = nil if @ask_sudo_pass == UNSET_VALUE
|
|
|
|
@limit = nil if @limit == UNSET_VALUE
|
|
|
|
@sudo = nil if @sudo == UNSET_VALUE
|
|
|
|
@sudo_user = nil if @sudo_user == UNSET_VALUE
|
|
|
|
@verbose = nil if @verbose == UNSET_VALUE
|
2013-05-06 19:17:45 +00:00
|
|
|
@tags = nil if @tags == UNSET_VALUE
|
2013-05-06 20:28:20 +00:00
|
|
|
@raw_arguments = nil if @raw_arguments == UNSET_VALUE
|
2013-03-20 14:41:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate(machine)
|
|
|
|
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-04-05 16:40:32 +00:00
|
|
|
# Validate that extra_vars is a hash, if set
|
|
|
|
if extra_vars
|
2013-04-05 16:43:56 +00:00
|
|
|
if !extra_vars.kind_of?(Hash)
|
2013-04-05 16:40:32 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.ansible.extra_vars_not_hash")
|
|
|
|
end
|
|
|
|
end
|
2013-04-05 16:43:56 +00:00
|
|
|
|
2013-04-04 06:07:07 +00:00
|
|
|
# Validate the existence of the inventory_file, if specified
|
|
|
|
if inventory_file
|
|
|
|
expanded_path = Pathname.new(inventory_file).expand_path(machine.env.root_path)
|
|
|
|
if !expanded_path.file?
|
|
|
|
errors << I18n.t("vagrant.provisioners.ansible.inventory_file_path_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
|