From 9da5043f18330c0199d0b633711998ad52679d46 Mon Sep 17 00:00:00 2001 From: Jeremy Price Date: Wed, 9 Oct 2013 12:47:14 -0400 Subject: [PATCH 1/2] Adding path_prefix to run_command so that one can pass in a path to the run environment if you nees something in a non-default path. --- lib/ansible/module_common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 648af8ff282..76c91b074a0 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -900,7 +900,7 @@ class AnsibleModule(object): # rename might not preserve context self.set_context_if_different(dest, context, False) - def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None, binary_data=False): + def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None, binary_data=False, path_prefix=None): ''' Execute a command, returns rc, stdout, and stderr. args is the command to run @@ -924,6 +924,10 @@ class AnsibleModule(object): rc = 0 msg = None st_in = None + env=os.environ + if path_prefix: + env['PATH']="%s:%s" % (path_prefix, env['PATH']) + if data: st_in = subprocess.PIPE try: @@ -933,7 +937,8 @@ class AnsibleModule(object): close_fds=close_fds, stdin=st_in, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE, + env=env) if data: if not binary_data: data += '\\n' From 3955b8e9c26b509903ef8acd3bde0cb8daad0738 Mon Sep 17 00:00:00 2001 From: Jeremy Price Date: Wed, 9 Oct 2013 12:50:18 -0400 Subject: [PATCH 2/2] Adding the bin/ directory of the virtualenv (if you specify a virtualenv) as a path_prefix so that other programs that only exist in the virtualenv will be available to things being installed into said virtualenv. Classic example: installing gevent requires cython binary to be available, but if cython is in the virtualenv only it won't be found without this. --- library/packaging/pip | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/packaging/pip b/library/packaging/pip index 33d31249712..08b8dec3ed3 100644 --- a/library/packaging/pip +++ b/library/packaging/pip @@ -234,6 +234,16 @@ def main(): pip = _get_pip(module, env) cmd = '%s %s' % (pip, state_map[state]) + + # If there's a virtualenv we want things we install to be able to use other + # installations that exist as binaries within this virtualenv. Example: we + # install cython and then gevent -- gevent needs to use the cython binary, + # not just a python package that will be found by calling the right python. + # So if there's a virtualenv, we add that bin/ to the beginning of the PATH + # in run_command by setting path_prefix here. + path_prefix = None + if env: + path_prefix="/".join(pip.split('/')[:-1]) if extra_args: cmd += ' %s' % extra_args @@ -279,7 +289,7 @@ def main(): os.chdir(tempfile.gettempdir()) if chdir: os.chdir(chdir) - rc, out_pip, err_pip = module.run_command(cmd) + rc, out_pip, err_pip = module.run_command(cmd, path_prefix=path_prefix) out += out_pip err += err_pip if rc == 1 and state == 'absent' and 'not installed' in out_pip: