1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.

This commit is contained in:
Jeremy Price 2013-10-09 12:47:14 -04:00
parent c55107fa83
commit 9da5043f18

View file

@ -900,7 +900,7 @@ class AnsibleModule(object):
# rename might not preserve context # rename might not preserve context
self.set_context_if_different(dest, context, False) 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. Execute a command, returns rc, stdout, and stderr.
args is the command to run args is the command to run
@ -924,6 +924,10 @@ class AnsibleModule(object):
rc = 0 rc = 0
msg = None msg = None
st_in = None st_in = None
env=os.environ
if path_prefix:
env['PATH']="%s:%s" % (path_prefix, env['PATH'])
if data: if data:
st_in = subprocess.PIPE st_in = subprocess.PIPE
try: try:
@ -933,7 +937,8 @@ class AnsibleModule(object):
close_fds=close_fds, close_fds=close_fds,
stdin=st_in, stdin=st_in,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE,
env=env)
if data: if data:
if not binary_data: if not binary_data:
data += '\\n' data += '\\n'