2016-05-25 07:12:14 +00:00
|
|
|
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
|
2016-09-20 20:58:41 +00:00
|
|
|
supported_options = %w( config_file
|
|
|
|
extra_vars
|
2016-05-25 07:12:14 +00:00
|
|
|
galaxy_command
|
|
|
|
galaxy_role_file
|
|
|
|
galaxy_roles_path
|
|
|
|
groups
|
|
|
|
host_vars
|
|
|
|
install
|
2016-06-08 20:59:47 +00:00
|
|
|
install_mode
|
2016-05-25 07:12:14 +00:00
|
|
|
inventory_path
|
|
|
|
limit
|
2017-01-06 13:19:44 +00:00
|
|
|
pip_args
|
2016-05-25 07:12:14 +00:00
|
|
|
playbook
|
2016-10-09 18:48:50 +00:00
|
|
|
playbook_command
|
2016-05-25 07:12:14 +00:00
|
|
|
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
|
2016-06-08 20:59:47 +00:00
|
|
|
expect(subject.install_mode).to eql(:default)
|
2016-05-25 07:12:14 +00:00
|
|
|
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
|
provisioners/ansible(both): fix ansible config files presence checks
With this change, the presence of Ansible configuration files (like
playbook file, inventory path, galaxy role file, etc.) is no longer
performed by the `config` classes, but by the `provisioner` classes
(at the beginning of the provision command).
This change fixes several issues:
- Resolve #6984 as `provision` method are only executed when remote
(ssh) communication with the guest machine is possible.
- Resolve #6763 in a better way than 4e451c6 initially did.
- Improve the general provisioner speed since the `config` checks are
actually triggered by many vagrant actions (e.g. `destroy`,...), and
can also be triggered multiple times during a vagrant run (e.g. on
callback request made by the machine provider).
Unlike the former `config`-based checks, the provision action won't
collect all the invalid options, but only report the first invalid
option found and abort the execution.
Some unit tests were not implemented yet to save my scarce "open source
contribution time" for other important issues, but they should be done
at last via GH-6633.
2016-05-31 22:30:07 +00:00
|
|
|
subject.playbook = existing_file
|
2016-05-25 07:12:14 +00:00
|
|
|
end
|
|
|
|
|
provisioners/ansible(both): fix ansible config files presence checks
With this change, the presence of Ansible configuration files (like
playbook file, inventory path, galaxy role file, etc.) is no longer
performed by the `config` classes, but by the `provisioner` classes
(at the beginning of the provision command).
This change fixes several issues:
- Resolve #6984 as `provision` method are only executed when remote
(ssh) communication with the guest machine is possible.
- Resolve #6763 in a better way than 4e451c6 initially did.
- Improve the general provisioner speed since the `config` checks are
actually triggered by many vagrant actions (e.g. `destroy`,...), and
can also be triggered multiple times during a vagrant run (e.g. on
callback request made by the machine provider).
Unlike the former `config`-based checks, the provision action won't
collect all the invalid options, but only report the first invalid
option found and abort the execution.
Some unit tests were not implemented yet to save my scarce "open source
contribution time" for other important issues, but they should be done
at last via GH-6633.
2016-05-31 22:30:07 +00:00
|
|
|
it_behaves_like "an Ansible provisioner", "/vagrant", "local"
|
2016-06-08 20:59:47 +00:00
|
|
|
|
|
|
|
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
|
ansible_local: Add the :pip_args_only install mode
With the introduction of `pip_args` option, you can easily extend the
`:pip` installation mode behaviour. But some interesting/advanced usages
are still not possible because of the auto-generated parts ("ansible"
package, version selection, and the `--upgrade` flag).
By adding this "pip_args_only" install mode, it will be for instance
possible to:
- install unofficial releases, like release candidates published at
https://releases.ansible.com/
- install more pip packages (e.g. via a `requirements.txt` file), with
hash validation, etc.
Note that there is no config validation that requires `pip_args` option
to be defined when the :pip_args_only mode is selected. This would be
more elegant, and user friendly to raise a configuration error, but this
can wait. At least, running with an empty `pip_args` won't lead to any
command crash, since the rather dummy "pip install" shows an helper
notice and terminates with a zero (0) exit code.
This change is thought as a complement to the changes originally
proposed in pull request GH-8170.
2017-03-23 22:10:56 +00:00
|
|
|
|
|
|
|
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
|
2016-05-25 07:12:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|