diff --git a/plugins/provisioners/ansible/config/base.rb b/plugins/provisioners/ansible/config/base.rb index 04c703439..f14b15597 100644 --- a/plugins/provisioners/ansible/config/base.rb +++ b/plugins/provisioners/ansible/config/base.rb @@ -3,6 +3,8 @@ module VagrantPlugins module Config class Base < Vagrant.plugin("2", :config) + GALAXY_COMMAND_DEFAULT = "ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force" + attr_accessor :extra_vars attr_accessor :galaxy_role_file attr_accessor :galaxy_roles_path @@ -40,22 +42,22 @@ module VagrantPlugins end def finalize! - @extra_vars = nil if @extra_vars == UNSET_VALUE - @galaxy_role_file = nil if @galaxy_role_file == UNSET_VALUE - @galaxy_roles_path = nil if @galaxy_roles_path == UNSET_VALUE - @galaxy_command = "ansible-galaxy install --role-file=%{ROLE_FILE} --roles-path=%{ROLES_PATH} --force" if @galaxy_command == UNSET_VALUE - @groups = {} if @groups == UNSET_VALUE - @inventory_path = nil if @inventory_path == UNSET_VALUE - @limit = nil if @limit == UNSET_VALUE - @playbook = nil if @playbook == UNSET_VALUE - @raw_arguments = nil if @raw_arguments == UNSET_VALUE - @skip_tags = nil if @skip_tags == UNSET_VALUE - @start_at_task = nil if @start_at_task == UNSET_VALUE - @sudo = false if @sudo != true - @sudo_user = nil if @sudo_user == UNSET_VALUE - @tags = nil if @tags == UNSET_VALUE - @vault_password_file = nil if @vault_password_file == UNSET_VALUE - @verbose = false if @verbose == UNSET_VALUE + @extra_vars = nil if @extra_vars == UNSET_VALUE + @galaxy_role_file = nil if @galaxy_role_file == UNSET_VALUE + @galaxy_roles_path = nil if @galaxy_roles_path == UNSET_VALUE + @galaxy_command = GALAXY_COMMAND_DEFAULT if @galaxy_command == UNSET_VALUE + @groups = {} if @groups == UNSET_VALUE + @inventory_path = nil if @inventory_path == UNSET_VALUE + @limit = nil if @limit == UNSET_VALUE + @playbook = nil if @playbook == UNSET_VALUE + @raw_arguments = nil if @raw_arguments == UNSET_VALUE + @skip_tags = nil if @skip_tags == UNSET_VALUE + @start_at_task = nil if @start_at_task == UNSET_VALUE + @sudo = false if @sudo != true + @sudo_user = nil if @sudo_user == UNSET_VALUE + @tags = nil if @tags == UNSET_VALUE + @vault_password_file = nil if @vault_password_file == UNSET_VALUE + @verbose = false if @verbose == UNSET_VALUE end # Just like the normal configuration "validate" method except that diff --git a/plugins/provisioners/ansible/provisioner/base.rb b/plugins/provisioners/ansible/provisioner/base.rb index 0fc24ecfb..7a455b2bf 100644 --- a/plugins/provisioners/ansible/provisioner/base.rb +++ b/plugins/provisioners/ansible/provisioner/base.rb @@ -133,12 +133,12 @@ module VagrantPlugins end def get_galaxy_role_file(basedir) - Pathname.new(config.galaxy_role_file).expand_path(basedir) + File.expand_path(config.galaxy_role_file, basedir) end def get_galaxy_roles_path(basedir) if config.galaxy_roles_path - Pathname.new(config.galaxy_roles_path).expand_path(basedir) + File.expand_path(config.galaxy_roles_path, basedir) else File.join(Pathname.new(config.playbook).expand_path(basedir).parent, 'roles') end diff --git a/plugins/provisioners/ansible/provisioner/guest.rb b/plugins/provisioners/ansible/provisioner/guest.rb index 2397f66df..3d76e1fed 100644 --- a/plugins/provisioners/ansible/provisioner/guest.rb +++ b/plugins/provisioners/ansible/provisioner/guest.rb @@ -66,8 +66,8 @@ module VagrantPlugins def execute_ansible_galaxy_on_guest command_values = { - :ROLE_FILE => get_galaxy_role_file(config.provisioning_path), - :ROLES_PATH => get_galaxy_roles_path(config.provisioning_path) + :role_file => get_galaxy_role_file(config.provisioning_path), + :roles_path => get_galaxy_roles_path(config.provisioning_path) } remote_command = config.galaxy_command % command_values diff --git a/plugins/provisioners/ansible/provisioner/host.rb b/plugins/provisioners/ansible/provisioner/host.rb index 61e576c97..ccf72ca8e 100644 --- a/plugins/provisioners/ansible/provisioner/host.rb +++ b/plugins/provisioners/ansible/provisioner/host.rb @@ -25,6 +25,8 @@ module VagrantPlugins protected + VAGRANT_ARG_SEPARATOR = 'VAGRANT_ARG_SEP' + def warn_for_unsupported_platform if Vagrant::Util::Platform.windows? @machine.env.ui.warn(I18n.t("vagrant.provisioners.ansible.windows_not_supported_for_control_machine")) @@ -86,16 +88,15 @@ module VagrantPlugins def execute_ansible_galaxy_from_host command_values = { - :ROLE_FILE => get_galaxy_role_file(machine.env.root_path), - :ROLES_PATH => get_galaxy_roles_path(machine.env.root_path) + :role_file => get_galaxy_role_file(machine.env.root_path), + :roles_path => get_galaxy_roles_path(machine.env.root_path) } - arg_separator = '__VAGRANT_ARG_SEPARATOR__' - command_template = config.galaxy_command.gsub(' ', arg_separator) + command_template = config.galaxy_command.gsub(' ', VAGRANT_ARG_SEPARATOR) str_command = command_template % command_values - ui_running_ansible_command "galaxy", str_command.gsub(arg_separator, ' ') + ui_running_ansible_command "galaxy", str_command.gsub(VAGRANT_ARG_SEPARATOR, ' ') - command = str_command.split(arg_separator) + command = str_command.split(VAGRANT_ARG_SEPARATOR) command << { # Write stdout and stderr data, since it's the regular Ansible output notify: [:stdout, :stderr], diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 6bcb24689..aa452bff3 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2043,6 +2043,12 @@ en: Vagrant does not support detecting whether Ansible is installed for the guest OS running in the machine. Vagrant will assume it is installed and attempt to continue. + + If you'd like this provisioner to be improved, please + take a look at the Vagrant source code linked below and try + to contribute back support. Thank you! + + https://github.com/mitchellh/vagrant errors: ansible_command_failed: |- Ansible failed to complete successfully. Any error output should be @@ -2054,7 +2060,7 @@ en: If you haven't installed Ansible yet, please install Ansible on your Vagrant basebox, or enable the automated setup with the `install` option of this provisioner. Please check - http://docs.vagrantup.com/v2/provisioning/ansible_local.html + https://docs.vagrantup.com/v2/provisioning/ansible_local.html for more information. ansible_not_found_on_host: |- The Ansible software could not be found! Please verify @@ -2063,12 +2069,12 @@ en: If you haven't installed Ansible yet, please install Ansible on your host system. Vagrant can't do this for you in a safe and automated way. - Please check http://docs.ansible.com for more information. + Please check https://docs.ansible.com for more information. ansible_version_not_found_on_guest: |- The requested Ansible version (%{required_version}) was not found on the guest. Please check the ansible installation on your guest system, or adapt the `version` option of this provisioner in your Vagrantfile. - See http://docs.vagrantup.com/v2/provisioning/ansible_local.html + See https://docs.vagrantup.com/v2/provisioning/ansible_local.html for more information. extra_vars_invalid: |- `extra_vars` must be a hash or a path to an existing file. Received: %{value} (as %{type}) @@ -2087,7 +2093,7 @@ en: running_playbook: "Running ansible-playbook..." windows_not_supported_for_control_machine: |- Windows is not officially supported for the Ansible Control Machine. - Please check http://docs.ansible.com/intro_installation.html#control-machine-requirements + Please check https://docs.ansible.com/intro_installation.html#control-machine-requirements docker: not_running: "Docker is not running on the guest VM." diff --git a/website/docs/source/v2/provisioning/ansible_common.html.md b/website/docs/source/v2/provisioning/ansible_common.html.md index aca7c2c14..cb8daf55e 100644 --- a/website/docs/source/v2/provisioning/ansible_common.html.md +++ b/website/docs/source/v2/provisioning/ansible_common.html.md @@ -53,17 +53,15 @@ Some of these options are for advanced usage only and should not be used unless - `galaxy_command` (template string) - The command pattern used to install Galaxy roles when `galaxy_role_file` is set. - The following placeholders can be used in this command pattern: - - `%{ROLE_FILE}` is replaced by the absolute path to the `galaxy_role_file` option - - `%{ROLES_PATH}` is - * replaced by the absolute path to the `galaxy_roles_path` option when such option is defined - * replaced by the absolute path to a `roles` subdirectory sitting in the parent directory of the configured `playbook` file otherwise. + The following (optional) placeholders can be used in this command pattern: + - `%{role_file}` is replaced by the absolute path to the `galaxy_role_file` option + - `%{roles_path}` is + - replaced by the absolute path to the `galaxy_roles_path` option when such option is defined, or + - replaced by the absolute path to a `roles` subdirectory sitting in the `playbook` parent directory. By default, this option is set to - ``` - ansible-galaxy install --role-file=%{ROLE_FILE} --roles-path=%{ROLES_PATH} --force - ``` + `ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force` - `galaxy_role_file` (string) - The path to the Ansible Galaxy role file.