mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
Merge pull request #4413 from jerm/ansible
Add capability to pass in a PATH prefix to run_command and allow pip module to utilize that to make virtualenv bin/ available in pip installs
This commit is contained in:
commit
898de833b0
2 changed files with 36 additions and 9 deletions
|
@ -939,7 +939,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
|
||||
|
@ -963,16 +963,33 @@ class AnsibleModule(object):
|
|||
rc = 0
|
||||
msg = None
|
||||
st_in = None
|
||||
|
||||
# Set a temporart env path if a prefix is passed
|
||||
env=os.environ
|
||||
if path_prefix:
|
||||
env['PATH']="%s:%s" % (path_prefix, env['PATH'])
|
||||
|
||||
if data:
|
||||
st_in = subprocess.PIPE
|
||||
try:
|
||||
cmd = subprocess.Popen(args,
|
||||
executable=executable,
|
||||
shell=shell,
|
||||
close_fds=close_fds,
|
||||
stdin=st_in,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
if path_prefix is not None:
|
||||
cmd = subprocess.Popen(args,
|
||||
executable=executable,
|
||||
shell=shell,
|
||||
close_fds=close_fds,
|
||||
stdin=st_in,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=env)
|
||||
else:
|
||||
cmd = subprocess.Popen(args,
|
||||
executable=executable,
|
||||
shell=shell,
|
||||
close_fds=close_fds,
|
||||
stdin=st_in,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
|
||||
if data:
|
||||
if not binary_data:
|
||||
data += '\\n'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue