From 1e38be237e421bc0fa6dcc55d8e600fb5b41ade9 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Tue, 5 Jan 2016 08:22:10 +0100 Subject: [PATCH] provisioners/ansible: fix galaxy paths on Windows Close #6757 and update previous fix for #6740 (#6741). See also these places where the same regexp is used to address similar "Windows cases": - https://github.com/mitchellh/vagrant/blob/ec85548bd6eabf0c9cddef615abc77ae7b913e02/plugins/provisioners/chef/provisioner/chef_solo.rb#L99-L103 - https://github.com/mitchellh/vagrant/blob/ec85548bd6eabf0c9cddef615abc77ae7b913e02/plugins/guests/windows/cap/rsync.rb#L6-L9 --- CHANGELOG.md | 4 ++-- plugins/provisioners/ansible/config/guest.rb | 5 +---- plugins/provisioners/ansible/helpers.rb | 6 ++++++ plugins/provisioners/ansible/provisioner/base.rb | 11 ++++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4dc1eaf1..f8729dc8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ BUG FIXES: - - provisioners/ansible_local: Fix error in `playbook` existence check when - running on a Windows host [GH-6740] + - provisioners/ansible_local: Fix errors in absolute paths to playbook or + galaxy resources when running on a Windows host [GH-6740, GH-6757] ## 1.8.1 (December 21, 2015) diff --git a/plugins/provisioners/ansible/config/guest.rb b/plugins/provisioners/ansible/config/guest.rb index bfd9444ce..1845870ca 100644 --- a/plugins/provisioners/ansible/config/guest.rb +++ b/plugins/provisioners/ansible/config/guest.rb @@ -37,10 +37,7 @@ module VagrantPlugins protected def check_path(machine, path, test_args, error_message_key = nil) - remote_path = File.expand_path(path, @provisioning_path) - - # Remove drive letter if running on a Windows host - remote_path = remote_path.gsub(/^[a-zA-Z]:/, "") + remote_path = Helpers::expand_path_in_unix_style(path, @provisioning_path) if machine.communicate.ready? && !machine.communicate.test("test #{test_args} #{remote_path}") if error_message_key diff --git a/plugins/provisioners/ansible/helpers.rb b/plugins/provisioners/ansible/helpers.rb index 1bdb57366..9795ab923 100644 --- a/plugins/provisioners/ansible/helpers.rb +++ b/plugins/provisioners/ansible/helpers.rb @@ -25,6 +25,12 @@ module VagrantPlugins shell_command += shell_arg.join(' ') end + def self.expand_path_in_unix_style(path, base_dir) + # Remove the possible drive letter, which is added + # by `File.expand_path` when running on a Windows host + File.expand_path(path, base_dir).sub(/^[a-zA-Z]:/, "") + end + def self.as_list_argument(v) v.kind_of?(Array) ? v.join(',') : v end diff --git a/plugins/provisioners/ansible/provisioner/base.rb b/plugins/provisioners/ansible/provisioner/base.rb index 291df8213..813f96a3e 100644 --- a/plugins/provisioners/ansible/provisioner/base.rb +++ b/plugins/provisioners/ansible/provisioner/base.rb @@ -179,15 +179,16 @@ module VagrantPlugins end end - def get_galaxy_role_file(basedir) - File.expand_path(config.galaxy_role_file, basedir) + def get_galaxy_role_file(base_dir) + Helpers::expand_path_in_unix_style(config.galaxy_role_file, base_dir) end - def get_galaxy_roles_path(basedir) + def get_galaxy_roles_path(base_dir) if config.galaxy_roles_path - File.expand_path(config.galaxy_roles_path, basedir) + Helpers::expand_path_in_unix_style(config.galaxy_roles_path, base_dir) else - File.join(Pathname.new(config.playbook).expand_path(basedir).parent, 'roles') + playbook_path = Helpers::expand_path_in_unix_style(config.playbook, base_dir) + File.join(Pathname.new(playbook_path).parent, 'roles') end end