From cf908d35e0454b80a11f3094d9e43ebfa33dbd8d Mon Sep 17 00:00:00 2001
From: Gilles Cornu <git@gilles.cornu.name>
Date: Sun, 24 Apr 2016 00:26:59 +0200
Subject: [PATCH] provisioners/ansible_local: Run galaxy from
 `provisioning_path` directory

Since it is now possible to specify some Galaxy settings in an
`ansible.cfg` file, it makes sense to run `ansible-galaxy` from the
same working directory as `ansible-playbook` execution does.

See http://docs.ansible.com/ansible/intro_configuration.html#galaxy-settings
---
 CHANGELOG.md                                          |  4 +++-
 plugins/provisioners/ansible/provisioner/guest.rb     | 11 ++++++-----
 .../source/docs/provisioning/ansible_local.html.md    |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7ebb746f9..1d9af152a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,7 +24,9 @@ IMPROVEMENTS:
   - commands/login: Print a warning with both the environment variable and
       local login token are present [GH-7206, GH-7219]
   - communicators/winrm: Upgrade to latest WinRM gems [GH-6922]
-  - provisioners/ansible(both provisioners): add basic config validators/converters
+  - provisioners/ansible_local: Use `provisioning_path` as working directory
+      for `ansible-galaxy` execution
+  - provisioners/ansible(both provisioners): Add basic config validators/converters
       on `raw_arguments` and `raw_ssh_args` options [GH-7103]
   - provisioners/chef: Add the ability to install on SUSE [GH-6806]
   - hosts/darwin: Add `extra_args` support for RDP [GH-5523, GH-6602]
diff --git a/plugins/provisioners/ansible/provisioner/guest.rb b/plugins/provisioners/ansible/provisioner/guest.rb
index a6dda8131..ade03151e 100644
--- a/plugins/provisioners/ansible/provisioner/guest.rb
+++ b/plugins/provisioners/ansible/provisioner/guest.rb
@@ -69,6 +69,7 @@ module VagrantPlugins
             :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
 
           execute_ansible_command_on_guest "galaxy", remote_command
@@ -78,15 +79,15 @@ module VagrantPlugins
           prepare_common_command_arguments
           prepare_common_environment_variables
 
-          remote_command = "cd #{config.provisioning_path} && #{ansible_playbook_command_for_shell_execution}"
-
-          execute_ansible_command_on_guest "playbook", remote_command
+          execute_ansible_command_on_guest "playbook", ansible_playbook_command_for_shell_execution
         end
 
         def execute_ansible_command_on_guest(name, command)
-          ui_running_ansible_command name, command
+          remote_command = "cd #{config.provisioning_path} && #{command}"
 
-          result = execute_on_guest(command)
+          ui_running_ansible_command name, remote_command
+
+          result = execute_on_guest(remote_command)
           raise Ansible::Errors::AnsibleCommandFailed if result != 0
         end
 
diff --git a/website/source/docs/provisioning/ansible_local.html.md b/website/source/docs/provisioning/ansible_local.html.md
index 4d34f20e0..9ecc6f25f 100644
--- a/website/source/docs/provisioning/ansible_local.html.md
+++ b/website/source/docs/provisioning/ansible_local.html.md
@@ -71,7 +71,7 @@ This section lists the specific options for the Ansible Local provisioner. In ad
 
   **Attention:** There is no guarantee that this automated installation will replace a custom Ansible setup, that might be already present on the Vagrant box.
 
-- `provisioning_path` (string) - An absolute path on the guest machine where the Ansible files are stored. The `ansible-playbook` command is executed from this directory.
+- `provisioning_path` (string) - An absolute path on the guest machine where the Ansible files are stored. The `ansible-galaxy` and `ansible-playbook` commands are executed from this directory. This is the location to place an [ansible.cfg](http://docs.ansible.com/ansible/intro_configuration.html) file, in case you need it.
 
   The default value is `/vagrant`.