2014-03-21 11:02:23 +00:00
|
|
|
require_relative "../../../base"
|
2014-04-12 09:00:34 +00:00
|
|
|
require_relative "../support/shared/config"
|
2014-03-21 11:02:23 +00:00
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/provisioners/ansible/config")
|
|
|
|
|
|
|
|
describe VagrantPlugins::Ansible::Config do
|
|
|
|
include_context "unit"
|
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
let(:machine) { double("machine", env: Vagrant::Environment.new) }
|
2014-03-29 08:19:26 +00:00
|
|
|
let(:existing_file) { File.expand_path(__FILE__) }
|
|
|
|
let(:non_existing_file) { "/this/does/not/exist" }
|
|
|
|
|
|
|
|
it "supports a list of options" do
|
|
|
|
config_options = subject.public_methods(false).find_all { |i| i.to_s.end_with?('=') }
|
|
|
|
config_options.map! { |i| i.to_s.sub('=', '') }
|
|
|
|
supported_options = %w( ask_sudo_pass
|
|
|
|
extra_vars
|
|
|
|
groups
|
|
|
|
host_key_checking
|
|
|
|
inventory_path
|
|
|
|
limit
|
|
|
|
playbook
|
|
|
|
raw_arguments
|
|
|
|
raw_ssh_args
|
|
|
|
skip_tags
|
|
|
|
start_at_task
|
|
|
|
sudo
|
|
|
|
sudo_user
|
|
|
|
tags
|
|
|
|
verbose )
|
|
|
|
|
|
|
|
expect(config_options.sort).to eql(supported_options)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns default values to unset options" do
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
expect(subject.playbook).to be_nil
|
|
|
|
expect(subject.extra_vars).to be_nil
|
2014-04-12 09:00:34 +00:00
|
|
|
expect(subject.ask_sudo_pass).to be_false
|
2014-03-29 08:19:26 +00:00
|
|
|
expect(subject.limit).to be_nil
|
2014-04-12 09:00:34 +00:00
|
|
|
expect(subject.sudo).to be_false
|
2014-03-29 08:19:26 +00:00
|
|
|
expect(subject.sudo_user).to be_nil
|
|
|
|
expect(subject.verbose).to be_nil
|
|
|
|
expect(subject.tags).to be_nil
|
|
|
|
expect(subject.skip_tags).to be_nil
|
|
|
|
expect(subject.start_at_task).to be_nil
|
|
|
|
expect(subject.groups).to eq({})
|
2014-04-12 09:00:34 +00:00
|
|
|
expect(subject.host_key_checking).to be_false
|
2014-03-29 08:19:26 +00:00
|
|
|
expect(subject.raw_arguments).to be_nil
|
|
|
|
expect(subject.raw_ssh_args).to be_nil
|
|
|
|
end
|
2014-03-21 11:02:23 +00:00
|
|
|
|
2014-04-12 09:00:34 +00:00
|
|
|
describe "host_key_checking option" do
|
|
|
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :host_key_checking, false
|
|
|
|
end
|
|
|
|
describe "ask_sudo_pass option" do
|
|
|
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false
|
|
|
|
end
|
|
|
|
describe "sudo option" do
|
|
|
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :sudo, false
|
|
|
|
end
|
|
|
|
|
2014-03-21 11:02:23 +00:00
|
|
|
describe "#validate" do
|
2014-03-29 08:19:26 +00:00
|
|
|
before do
|
|
|
|
subject.playbook = existing_file
|
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if the playbook option refers to an existing file" do
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if the playbook option is undefined" do
|
|
|
|
subject.playbook = nil
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([
|
|
|
|
I18n.t("vagrant.provisioners.ansible.no_playbook")
|
|
|
|
])
|
|
|
|
end
|
2014-03-21 11:02:23 +00:00
|
|
|
|
2014-03-29 08:19:26 +00:00
|
|
|
it "returns an error if the playbook file does not exist" do
|
2014-03-21 11:02:23 +00:00
|
|
|
subject.playbook = non_existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([
|
|
|
|
I18n.t("vagrant.provisioners.ansible.playbook_path_invalid",
|
|
|
|
:path => non_existing_file)
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
2014-03-29 08:19:26 +00:00
|
|
|
it "passes if the extra_vars option refers to an existing file" do
|
|
|
|
subject.extra_vars = existing_file
|
|
|
|
subject.finalize!
|
2014-03-21 11:02:23 +00:00
|
|
|
|
2014-03-29 08:19:26 +00:00
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if the extra_vars option is a hash" do
|
|
|
|
subject.extra_vars = { var1: 1, var2: "foo" }
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if the extra_vars option refers to a file that does not exist" do
|
|
|
|
subject.extra_vars = non_existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([
|
|
|
|
I18n.t("vagrant.provisioners.ansible.extra_vars_invalid",
|
|
|
|
:type => subject.extra_vars.class.to_s,
|
|
|
|
:value => subject.extra_vars.to_s)
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if the extra_vars option is of wrong data type" do
|
|
|
|
subject.extra_vars = ["var1", 3, "var2", 5]
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([
|
|
|
|
I18n.t("vagrant.provisioners.ansible.extra_vars_invalid",
|
|
|
|
:type => subject.extra_vars.class.to_s,
|
|
|
|
:value => subject.extra_vars.to_s)
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if inventory_path refers to an existing location" do
|
|
|
|
subject.inventory_path = existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if inventory_path is specified, but does not exist" do
|
2014-03-21 11:02:23 +00:00
|
|
|
subject.inventory_path = non_existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to eql([
|
|
|
|
I18n.t("vagrant.provisioners.ansible.inventory_path_invalid",
|
|
|
|
:path => non_existing_file)
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
2014-03-29 08:19:26 +00:00
|
|
|
it "it collects and returns all detected errors" do
|
|
|
|
subject.playbook = non_existing_file
|
|
|
|
subject.inventory_path = non_existing_file
|
|
|
|
subject.extra_vars = non_existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible provisioner"]).to include(
|
|
|
|
I18n.t("vagrant.provisioners.ansible.playbook_path_invalid",
|
|
|
|
:path => non_existing_file))
|
|
|
|
expect(result["ansible provisioner"]).to include(
|
|
|
|
I18n.t("vagrant.provisioners.ansible.extra_vars_invalid",
|
|
|
|
:type => subject.extra_vars.class.to_s,
|
|
|
|
:value => subject.extra_vars.to_s))
|
|
|
|
expect(result["ansible provisioner"]).to include(
|
|
|
|
I18n.t("vagrant.provisioners.ansible.inventory_path_invalid",
|
|
|
|
:path => non_existing_file))
|
|
|
|
end
|
|
|
|
|
2014-03-21 11:02:23 +00:00
|
|
|
end
|
2014-03-29 08:19:26 +00:00
|
|
|
|
2014-03-21 11:02:23 +00:00
|
|
|
end
|