Make ansible-playbook command configurable

The ansible-playbook command is currently hardcoded for the ansible and
ansible_local provisioners. This patch adds the config option
playbook_command to allow the user to change the command.
This commit is contained in:
Daniel Gonzalez 2016-10-09 20:48:50 +02:00
parent d178631ff9
commit 58f2b0c8c7
5 changed files with 25 additions and 19 deletions

View File

@ -4,6 +4,7 @@ module VagrantPlugins
class Base < Vagrant.plugin("2", :config) class Base < Vagrant.plugin("2", :config)
GALAXY_COMMAND_DEFAULT = "ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force".freeze GALAXY_COMMAND_DEFAULT = "ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force".freeze
PLAYBOOK_COMMAND_DEFAULT = "ansible-playbook".freeze
attr_accessor :extra_vars attr_accessor :extra_vars
attr_accessor :galaxy_role_file attr_accessor :galaxy_role_file
@ -14,6 +15,7 @@ module VagrantPlugins
attr_accessor :inventory_path attr_accessor :inventory_path
attr_accessor :limit attr_accessor :limit
attr_accessor :playbook attr_accessor :playbook
attr_accessor :playbook_command
attr_accessor :raw_arguments attr_accessor :raw_arguments
attr_accessor :skip_tags attr_accessor :skip_tags
attr_accessor :start_at_task attr_accessor :start_at_task
@ -33,6 +35,7 @@ module VagrantPlugins
@inventory_path = UNSET_VALUE @inventory_path = UNSET_VALUE
@limit = UNSET_VALUE @limit = UNSET_VALUE
@playbook = UNSET_VALUE @playbook = UNSET_VALUE
@playbook_command = UNSET_VALUE
@raw_arguments = UNSET_VALUE @raw_arguments = UNSET_VALUE
@skip_tags = UNSET_VALUE @skip_tags = UNSET_VALUE
@start_at_task = UNSET_VALUE @start_at_task = UNSET_VALUE
@ -44,23 +47,24 @@ module VagrantPlugins
end end
def finalize! def finalize!
@extra_vars = nil if @extra_vars == UNSET_VALUE @extra_vars = nil if @extra_vars == UNSET_VALUE
@galaxy_role_file = nil if @galaxy_role_file == UNSET_VALUE @galaxy_role_file = nil if @galaxy_role_file == UNSET_VALUE
@galaxy_roles_path = nil if @galaxy_roles_path == UNSET_VALUE @galaxy_roles_path = nil if @galaxy_roles_path == UNSET_VALUE
@galaxy_command = GALAXY_COMMAND_DEFAULT if @galaxy_command == UNSET_VALUE @galaxy_command = GALAXY_COMMAND_DEFAULT if @galaxy_command == UNSET_VALUE
@host_vars = {} if @host_vars == UNSET_VALUE @host_vars = {} if @host_vars == UNSET_VALUE
@groups = {} if @groups == UNSET_VALUE @groups = {} if @groups == UNSET_VALUE
@inventory_path = nil if @inventory_path == UNSET_VALUE @inventory_path = nil if @inventory_path == UNSET_VALUE
@limit = nil if @limit == UNSET_VALUE @limit = nil if @limit == UNSET_VALUE
@playbook = nil if @playbook == UNSET_VALUE @playbook = nil if @playbook == UNSET_VALUE
@raw_arguments = nil if @raw_arguments == UNSET_VALUE @playbook_command = PLAYBOOK_COMMAND_DEFAULT if @playbook_command == UNSET_VALUE
@skip_tags = nil if @skip_tags == UNSET_VALUE @raw_arguments = nil if @raw_arguments == UNSET_VALUE
@start_at_task = nil if @start_at_task == UNSET_VALUE @skip_tags = nil if @skip_tags == UNSET_VALUE
@sudo = false if @sudo != true @start_at_task = nil if @start_at_task == UNSET_VALUE
@sudo_user = nil if @sudo_user == UNSET_VALUE @sudo = false if @sudo != true
@tags = nil if @tags == UNSET_VALUE @sudo_user = nil if @sudo_user == UNSET_VALUE
@vault_password_file = nil if @vault_password_file == UNSET_VALUE @tags = nil if @tags == UNSET_VALUE
@verbose = false if @verbose == UNSET_VALUE @vault_password_file = nil if @vault_password_file == UNSET_VALUE
@verbose = false if @verbose == UNSET_VALUE
end end
# Just like the normal configuration "validate" method except that # Just like the normal configuration "validate" method except that

View File

@ -44,7 +44,7 @@ module VagrantPlugins
end end
end end
shell_command << "ansible-playbook" shell_command << config.playbook_command
shell_args = [] shell_args = []
@command_arguments.each do |arg| @command_arguments.each do |arg|

View File

@ -113,7 +113,7 @@ module VagrantPlugins
prepare_environment_variables prepare_environment_variables
# Assemble the full ansible-playbook command # Assemble the full ansible-playbook command
command = %w(ansible-playbook) << @command_arguments command = [config.playbook_command] << @command_arguments
# Add the raw arguments at the end, to give them the highest precedence # Add the raw arguments at the end, to give them the highest precedence
command << config.raw_arguments if config.raw_arguments command << config.raw_arguments if config.raw_arguments

View File

@ -27,6 +27,7 @@ describe VagrantPlugins::Ansible::Config::Guest do
inventory_path inventory_path
limit limit
playbook playbook
playbook_command
provisioning_path provisioning_path
raw_arguments raw_arguments
skip_tags skip_tags

View File

@ -26,6 +26,7 @@ describe VagrantPlugins::Ansible::Config::Host, :skip_windows => true do
inventory_path inventory_path
limit limit
playbook playbook
playbook_command
raw_arguments raw_arguments
raw_ssh_args raw_ssh_args
skip_tags skip_tags