Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't hardcode chroot path #2952

Merged
merged 2 commits into from
May 19, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/ansible/runner/connection_plugins/chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
# 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
import shutil
import subprocess
import select
import fcntl
from ansible import errors
from ansible import utils
from ansible.callbacks import vvv
Expand All @@ -45,6 +43,10 @@ def __init__(self, runner, host, port, *args, **kwargs):
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
Expand All @@ -62,12 +64,10 @@ def exec_command(self, cmd, tmp_path, sudo_user, sudoable=False, executable='/bi

# 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),
Expand Down