From f52e3dee70bdfda9a4a09f174d89226fd61ed0e0 Mon Sep 17 00:00:00 2001
From: Maykel Moya <mmoya@speedyrails.com>
Date: Sat, 18 May 2013 23:09:38 +0200
Subject: [PATCH 1/2] Don't hardcode chroot executable path

---
 lib/ansible/runner/connection_plugins/chroot.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/ansible/runner/connection_plugins/chroot.py b/lib/ansible/runner/connection_plugins/chroot.py
index 14b3c06f7f..87b84279ea 100644
--- a/lib/ansible/runner/connection_plugins/chroot.py
+++ b/lib/ansible/runner/connection_plugins/chroot.py
@@ -16,6 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
 
+import distutils.spawn
 import traceback
 import os
 import pipes
@@ -45,6 +46,10 @@ class Connection(object):
         if not utils.is_executable(chrootsh):
             raise errors.AnsibleError("%s does not look like a chrootable dir (/bin/sh missing)" % self.chroot)
 
+        self.chroot_cmd = distutils.spawn.find_executable('chroot')
+        if not self.chroot_cmd:
+            raise errors.AnsibleError("chroot command not found in PATH")
+
         self.runner = runner
         self.host = host
         # port is unused, since this is local
@@ -62,12 +67,10 @@ class Connection(object):
 
         # We enter chroot as root so sudo stuff can be ignored
 
-        chroot_cmd = '/usr/sbin/chroot'
-
         if executable:
-            local_cmd = [chroot_cmd, self.chroot, executable, '-c', cmd]
+            local_cmd = [self.chroot_cmd, self.chroot, executable, '-c', cmd]
         else:
-            local_cmd = '%s "%s" %s' % (chroot_cmd, self.chroot, cmd)
+            local_cmd = '%s "%s" %s' % (self.chroot_cmd, self.chroot, cmd)
 
         vvv("EXEC %s" % (local_cmd), host=self.chroot)
         p = subprocess.Popen(local_cmd, shell=isinstance(local_cmd, basestring),

From 60f24bb077945e385aec221f63cc416b147aade9 Mon Sep 17 00:00:00 2001
From: Maykel Moya <mmoya@speedyrails.com>
Date: Sat, 18 May 2013 23:11:47 +0200
Subject: [PATCH 2/2] Remove unused modules

---
 lib/ansible/runner/connection_plugins/chroot.py | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/lib/ansible/runner/connection_plugins/chroot.py b/lib/ansible/runner/connection_plugins/chroot.py
index 87b84279ea..305e9eb06b 100644
--- a/lib/ansible/runner/connection_plugins/chroot.py
+++ b/lib/ansible/runner/connection_plugins/chroot.py
@@ -19,11 +19,8 @@
 import distutils.spawn
 import traceback
 import os
-import pipes
 import shutil
 import subprocess
-import select
-import fcntl
 from ansible import errors
 from ansible import utils
 from ansible.callbacks import vvv