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
|
|
|
|
2015-11-20 23:13:35 +00:00
|
|
|
require "vagrant/util/platform"
|
|
|
|
|
2015-02-10 14:28:00 +00:00
|
|
|
require Vagrant.source_root.join("plugins/provisioners/ansible/config/host")
|
2014-03-21 11:02:23 +00:00
|
|
|
|
2015-02-10 14:28:00 +00:00
|
|
|
describe VagrantPlugins::Ansible::Config::Host do
|
2014-03-21 11:02:23 +00:00
|
|
|
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__) }
|
2015-11-20 23:13:35 +00:00
|
|
|
let(:non_existing_file) do
|
|
|
|
next "/this/does/not/exist" if !Vagrant::Util::Platform.windows?
|
|
|
|
"C:/foo/nope/nope"
|
|
|
|
end
|
2014-03-29 08:19:26 +00:00
|
|
|
|
|
|
|
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('=', '') }
|
2015-02-10 14:28:00 +00:00
|
|
|
|
2014-03-29 08:19:26 +00:00
|
|
|
supported_options = %w( ask_sudo_pass
|
2014-04-14 03:24:57 +00:00
|
|
|
ask_vault_pass
|
2014-03-29 08:19:26 +00:00
|
|
|
extra_vars
|
2015-11-02 08:03:15 +00:00
|
|
|
force_remote_user
|
2015-11-17 21:06:06 +00:00
|
|
|
galaxy_command
|
|
|
|
galaxy_role_file
|
|
|
|
galaxy_roles_path
|
2014-03-29 08:19:26 +00:00
|
|
|
groups
|
|
|
|
host_key_checking
|
2015-12-01 16:04:56 +00:00
|
|
|
host_vars
|
2014-03-29 08:19:26 +00:00
|
|
|
inventory_path
|
|
|
|
limit
|
|
|
|
playbook
|
|
|
|
raw_arguments
|
|
|
|
raw_ssh_args
|
|
|
|
skip_tags
|
|
|
|
start_at_task
|
|
|
|
sudo
|
|
|
|
sudo_user
|
|
|
|
tags
|
2014-04-14 03:24:57 +00:00
|
|
|
vault_password_file
|
2014-03-29 08:19:26 +00:00
|
|
|
verbose )
|
|
|
|
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(get_provisioner_option_names(described_class)).to eql(supported_options)
|
2014-03-29 08:19:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns default values to unset options" do
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
expect(subject.playbook).to be_nil
|
|
|
|
expect(subject.extra_vars).to be_nil
|
2015-11-02 08:03:15 +00:00
|
|
|
expect(subject.force_remote_user).to be_true
|
2014-04-12 09:00:34 +00:00
|
|
|
expect(subject.ask_sudo_pass).to be_false
|
2014-04-14 03:24:57 +00:00
|
|
|
expect(subject.ask_vault_pass).to be_false
|
|
|
|
expect(subject.vault_password_file).to be_nil
|
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
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(subject.verbose).to be_false
|
2014-03-29 08:19:26 +00:00
|
|
|
expect(subject.tags).to be_nil
|
|
|
|
expect(subject.skip_tags).to be_nil
|
|
|
|
expect(subject.start_at_task).to be_nil
|
2015-12-01 16:04:56 +00:00
|
|
|
expect(subject.host_vars).to eq({})
|
2014-03-29 08:19:26 +00:00
|
|
|
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
|
|
|
|
2015-11-02 08:03:15 +00:00
|
|
|
describe "force_remote_user option" do
|
|
|
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :force_remote_user, true
|
|
|
|
end
|
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
|
2014-04-14 03:24:57 +00:00
|
|
|
describe "ask_vault_pass option" do
|
|
|
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false
|
|
|
|
end
|
2014-04-12 09:00:34 +00:00
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([])
|
2014-03-29 08:19:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if the playbook option is undefined" do
|
|
|
|
subject.playbook = nil
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.no_playbook")
|
2014-03-29 08:19:26 +00:00
|
|
|
])
|
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.playbook_path_invalid",
|
2015-02-10 14:28:00 +00:00
|
|
|
path: non_existing_file, system: "host")
|
2014-03-21 11:02:23 +00:00
|
|
|
])
|
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([])
|
2014-03-29 08:19:26 +00:00
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([])
|
2014-03-29 08:19:26 +00:00
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.extra_vars_invalid",
|
2014-05-22 16:35:12 +00:00
|
|
|
type: subject.extra_vars.class.to_s,
|
|
|
|
value: subject.extra_vars.to_s)
|
2014-03-29 08:19:26 +00:00
|
|
|
])
|
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.extra_vars_invalid",
|
2014-05-22 16:35:12 +00:00
|
|
|
type: subject.extra_vars.class.to_s,
|
|
|
|
value: subject.extra_vars.to_s)
|
2014-03-29 08:19:26 +00:00
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "passes if inventory_path refers to an existing location" do
|
|
|
|
subject.inventory_path = existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([])
|
2014-03-29 08:19:26 +00:00
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.inventory_path_invalid",
|
2015-02-10 14:28:00 +00:00
|
|
|
path: non_existing_file, system: "host")
|
2014-03-21 11:02:23 +00:00
|
|
|
])
|
|
|
|
end
|
|
|
|
|
2014-04-14 03:24:57 +00:00
|
|
|
it "returns an error if vault_password_file is specified, but does not exist" do
|
|
|
|
subject.vault_password_file = non_existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to eql([
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.vault_password_file_invalid",
|
|
|
|
path: non_existing_file, system: "host")
|
2015-11-17 21:06:06 +00:00
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error if galaxy_role_file is specified, but does not exist" do
|
|
|
|
subject.galaxy_role_file = non_existing_file
|
|
|
|
subject.finalize!
|
|
|
|
|
|
|
|
result = subject.validate(machine)
|
|
|
|
expect(result["ansible remote provisioner"]).to eql([
|
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.galaxy_role_file_invalid",
|
2015-02-10 14:28:00 +00:00
|
|
|
path: non_existing_file, system: "host")
|
2014-04-14 03:24:57 +00:00
|
|
|
])
|
|
|
|
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)
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to include(
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.playbook_path_invalid",
|
2015-02-10 14:28:00 +00:00
|
|
|
path: non_existing_file, system: "host"))
|
|
|
|
expect(result["ansible remote provisioner"]).to include(
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.extra_vars_invalid",
|
2014-05-22 16:35:12 +00:00
|
|
|
type: subject.extra_vars.class.to_s,
|
|
|
|
value: subject.extra_vars.to_s))
|
2015-02-10 14:28:00 +00:00
|
|
|
expect(result["ansible remote provisioner"]).to include(
|
2015-11-17 06:55:32 +00:00
|
|
|
I18n.t("vagrant.provisioners.ansible.errors.inventory_path_invalid",
|
2015-02-10 14:28:00 +00:00
|
|
|
path: non_existing_file, system: "host"))
|
2014-03-29 08:19:26 +00:00
|
|
|
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
|