mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
- make tmp_path be a dir so we can put more than one command in there securely
This commit is contained in:
parent
8fc69d3055
commit
85f751175d
1 changed files with 12 additions and 8 deletions
|
@ -76,6 +76,7 @@ class Runner(object):
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.remote_user = remote_user
|
self.remote_user = remote_user
|
||||||
self.remote_pass = remote_pass
|
self.remote_pass = remote_pass
|
||||||
|
self._tmp_paths = {}
|
||||||
|
|
||||||
def _parse_hosts(self, host_list):
|
def _parse_hosts(self, host_list):
|
||||||
''' parse the host inventory file if not sent as an array '''
|
''' parse the host inventory file if not sent as an array '''
|
||||||
|
@ -189,7 +190,8 @@ class Runner(object):
|
||||||
dest = options['dest']
|
dest = options['dest']
|
||||||
|
|
||||||
# transfer the file to a remote tmp location
|
# transfer the file to a remote tmp location
|
||||||
tmp_src = self._get_tmp_path(conn, dest.split("/")[-1])
|
tmp_path = self._get_tmp_path(conn)
|
||||||
|
tmp_src = tmp_path + source.split('/')[-1]
|
||||||
self._transfer_file(conn, source, tmp_src)
|
self._transfer_file(conn, source, tmp_src)
|
||||||
|
|
||||||
# install the copy module
|
# install the copy module
|
||||||
|
@ -213,7 +215,7 @@ class Runner(object):
|
||||||
|
|
||||||
# first copy the source template over
|
# first copy the source template over
|
||||||
tempname = os.path.split(source)[-1]
|
tempname = os.path.split(source)[-1]
|
||||||
temppath = self._get_tmp_path(conn, tempname)
|
temppath = self._get_tmp_path(conn) + tempname
|
||||||
self._transfer_file(conn, source, temppath)
|
self._transfer_file(conn, source, temppath)
|
||||||
|
|
||||||
# install the template module
|
# install the template module
|
||||||
|
@ -261,7 +263,6 @@ class Runner(object):
|
||||||
def remote_log(self, conn, msg):
|
def remote_log(self, conn, msg):
|
||||||
''' this is the function we use to log things '''
|
''' this is the function we use to log things '''
|
||||||
stdin, stdout, stderr = conn.exec_command('/usr/bin/logger -t ansible -p auth.info %r' % msg)
|
stdin, stdout, stderr = conn.exec_command('/usr/bin/logger -t ansible -p auth.info %r' % msg)
|
||||||
# TODO: doesn't actually call logger on the remote box, should though
|
|
||||||
# TODO: maybe make that optional
|
# TODO: maybe make that optional
|
||||||
|
|
||||||
def _exec_command(self, conn, cmd):
|
def _exec_command(self, conn, cmd):
|
||||||
|
@ -272,18 +273,21 @@ class Runner(object):
|
||||||
results = "\n".join(stdout.readlines())
|
results = "\n".join(stdout.readlines())
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _get_tmp_path(self, conn, file_name):
|
def _get_tmp_path(self, conn):
|
||||||
''' gets a temporary path on a remote box '''
|
''' gets a temporary path on a remote box '''
|
||||||
output = self._exec_command(conn, "mktemp /tmp/%s.XXXXXX" % file_name)
|
|
||||||
return output.split("\n")[0]
|
if conn not in self._tmp_paths:
|
||||||
|
output = self._exec_command(conn, "mktemp -d /tmp/ansible.XXXXXX")
|
||||||
|
self._tmp_paths[conn] = output.split("\n")[0] + '/'
|
||||||
|
|
||||||
|
return self._tmp_paths[conn]
|
||||||
|
|
||||||
def _copy_module(self, conn):
|
def _copy_module(self, conn):
|
||||||
''' transfer a module over SFTP, does not run it '''
|
''' transfer a module over SFTP, does not run it '''
|
||||||
in_path = os.path.expanduser(
|
in_path = os.path.expanduser(
|
||||||
os.path.join(self.module_path, self.module_name)
|
os.path.join(self.module_path, self.module_name)
|
||||||
)
|
)
|
||||||
out_path = self._get_tmp_path(conn, "ansible_%s" % self.module_name)
|
out_path = self._get_tmp_path(conn) + self.module_name
|
||||||
|
|
||||||
sftp = conn.open_sftp()
|
sftp = conn.open_sftp()
|
||||||
sftp.put(in_path, out_path)
|
sftp.put(in_path, out_path)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
|
Loading…
Reference in a new issue