|
|
@ -17,6 +17,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
import pipes
|
|
|
|
import shutil
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
from ansible import errors
|
|
|
|
from ansible import errors
|
|
|
@ -36,20 +37,22 @@ class Connection(object):
|
|
|
|
|
|
|
|
|
|
|
|
return self
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
|
|
def exec_command(self, cmd, tmp_path, sudo_user, sudoable=False):
|
|
|
|
def exec_command(self, cmd, tmp_path, sudo_user, sudoable=False, executable='/bin/sh'):
|
|
|
|
''' run a command on the local host '''
|
|
|
|
''' run a command on the local host '''
|
|
|
|
|
|
|
|
|
|
|
|
if self.runner.sudo and sudoable:
|
|
|
|
if not self.runner.sudo or not sudoable:
|
|
|
|
|
|
|
|
local_cmd = [ executable, '-c', cmd]
|
|
|
|
|
|
|
|
else:
|
|
|
|
if self.runner.sudo_pass:
|
|
|
|
if self.runner.sudo_pass:
|
|
|
|
# NOTE: if someone wants to add sudo w/ password to the local connection type, they are welcome
|
|
|
|
# NOTE: if someone wants to add sudo w/ password to the local connection type, they are welcome
|
|
|
|
# to do so. The primary usage of the local connection is for crontab and kickstart usage however
|
|
|
|
# to do so. The primary usage of the local connection is for crontab and kickstart usage however
|
|
|
|
# so this doesn't seem to be a huge priority
|
|
|
|
# so this doesn't seem to be a huge priority
|
|
|
|
raise errors.AnsibleError("sudo with password is presently only supported on the 'paramiko' (SSH) and native 'ssh' connection types")
|
|
|
|
raise errors.AnsibleError("sudo with password is presently only supported on the 'paramiko' (SSH) and native 'ssh' connection types")
|
|
|
|
cmd = "sudo -u {0} -s {1}".format(sudo_user, cmd)
|
|
|
|
sudocmd = "sudo -u %s -s %s -c %s" % (sudo_user, executable, cmd)
|
|
|
|
|
|
|
|
local_cmd = ['/bin/sh', '-c', sudocmd]
|
|
|
|
|
|
|
|
|
|
|
|
vvv("EXEC %s" % cmd, host=self.host)
|
|
|
|
vvv("EXEC %s" % local_cmd, host=self.host)
|
|
|
|
basedir = self.runner.basedir
|
|
|
|
p = subprocess.Popen(local_cmd, cwd=self.runner.basedir, executable=executable,
|
|
|
|
p = subprocess.Popen(cmd, cwd=basedir, shell=True, stdin=None,
|
|
|
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
return (p.returncode, '', stdout, stderr)
|
|
|
|
return (p.returncode, '', stdout, stderr)
|
|
|
|