vagrant/test/unit/plugins/provisioners/ansible/config/guest_test.rb

98 lines
3.0 KiB
Ruby
Raw Normal View History

require_relative "../../../../base"
require_relative "../../support/shared/config"
require_relative "shared"
require Vagrant.source_root.join("plugins/provisioners/ansible/config/guest")
describe VagrantPlugins::Ansible::Config::Guest do
include_context "unit"
subject { described_class.new }
# FIXME: machine.ui.warn stub is not working as expected...
let(:machine) { double("machine", env: Vagrant::Environment.new) }
let(:communicator) { double("communicator") }
let(:existing_file) { "this/path/is/a/stub" }
it "supports a list of options" do
provisioners/ansible(both): Add compatibility mode With this change, it is now possible to get rid of many deprecation messages successively introduced in Ansible 1.9, and 2.0. More interesting, the generated inventory will contain the recommended variable names (e.g. `ansible_host` instead of `ansible_ssh_host`) when the compatibility mode is set to '2.0'. Details: - Add `compatibility_mode` option to control the Ansible parameters format to be used. The value corresponds to the minimal version supported. For the moment, possible values are '1.8' (corresponding to Vagrant's former behaviour) or '2.0'. Note that a dynamic inventory generated in compatibility mode '2.0' is not supported by Ansible 1.x. On the other hand, Ansible 2.x so far supports inventory format generated by the compatibility mode '1.8'. - Add compatibility mode auto-detection, based on the available Ansible version. This is the default behaviour in order to bring a maximum of user friendliness. The drawback of this approach is to let potential compatibility breaking risks, for `ansible` provisioner setups that already integrate Ansible 2.x **AND** rely on the existence of the generated `_ssh` variable names. Thanks to the vagrant warnings (and its release notes), I argue that it is worth to offer auto-detection by default, which offers a sweet transition to most users. - Add `become`, `become_user` and `ask_become_pass` options and their backwards compatible aliases. The legacy options are now deprecated. Note that we intentionally didn't provide a '1.9' compatibility mode, as it would add extra-complexity for practically no added-value. To my knowledge, the Ansible 2.x series haven't introduced yet any major changes or deprecations that would motivate to introduce a higher version compatibility mode (to be confirmed/verified). Resolve GH-6570 Still Pending: - Optimization: Reduce the number of `ansible` command executions. Currently two exec calls will be performed when the compatibility mode auto-detection is enabled (i.e. by default). We could make the provisioner a little bit smarter to only execute `ansible` only once in any situation (by combining "presence" and "version" checks). - User-friendliness: Add better validator on `compatibility_mode` option, and shows a warning or an error instead of the silent fallback on the auto-detection modus. - Test coverage: All the added behaviours are not fully covered yet.
2016-11-13 19:58:26 +00:00
supported_options = %w( become
become_user
compatibility_mode
config_file
extra_vars
galaxy_command
galaxy_role_file
galaxy_roles_path
groups
host_vars
install
install_mode
inventory_path
limit
pip_args
playbook
playbook_command
provisioning_path
raw_arguments
skip_tags
start_at_task
sudo
sudo_user
tags
tmp_path
vault_password_file
verbose
version )
expect(get_provisioner_option_names(described_class)).to eql(supported_options)
end
describe "default options handling" do
it_behaves_like "options shared by both Ansible provisioners"
it "assigns default values to unset guest-specific options" do
subject.finalize!
expect(subject.install).to be(true)
expect(subject.install_mode).to eql(:default)
expect(subject.provisioning_path).to eql("/vagrant")
expect(subject.tmp_path).to eql("/tmp/vagrant-ansible")
expect(subject.version).to be_empty
end
end
describe "#validate" do
before do
subject.playbook = existing_file
end
it_behaves_like "an Ansible provisioner", "/vagrant", "local"
it "falls back to :default install_mode for any invalid setting" do
subject.install_mode = "from_source"
subject.finalize!
result = subject.validate(machine)
expect(subject.install_mode).to eql(:default)
end
it "supports :pip install_mode" do
subject.install_mode = "pip"
subject.finalize!
result = subject.validate(machine)
expect(subject.install_mode).to eql(:pip)
end
it "supports :pip_args_only install_mode" do
subject.install_mode = "pip_args_only"
subject.finalize!
result = subject.validate(machine)
expect(subject.install_mode).to eql(:pip_args_only)
end
end
end