Split argsfile handling into subfunction, attempt to apply argsfile logic to setup

pull/70/head
Michael DeHaan 12 years ago
parent 1f53c89b14
commit 3ea9174ed7

@ -35,6 +35,7 @@ import jinja2
import time
import traceback
import tempfile
import StringIO
# FIXME: stop importing *, use as utils/errors
from ansible.utils import *
@ -227,7 +228,6 @@ class Runner(object):
def _transfer_file(self, conn, source, dest):
''' transfers a remote file '''
self.remote_log(conn, 'COPY remote:%s local:%s' % (source, dest))
conn.put_file(source, dest)
# *****************************************************
@ -244,6 +244,23 @@ class Runner(object):
# *****************************************************
def _transfer_argsfile(self, conn, tmp, args_str):
'''
transfer arguments as a single file to be fed to the module.
this is to avoid various shell things being eaten by SSH
'''
args_fd, args_file = tempfile.mkstemp()
args_fo = os.fdopen(args_fd, 'w')
args_fo.write(args_str)
args_fo.flush()
args_fo.close()
args_remote = os.path.join(tmp, 'arguments')
self._transfer_file(conn, args_file, 'arguments')
os.unlink(args_file)
return args_remote
# *****************************************************
def _execute_module(self, conn, tmp, remote_module_path, module_args):
'''
runs a module that has already been transferred, but first
@ -268,17 +285,8 @@ class Runner(object):
template = jinja2.Template(args)
args = template.render(inject_vars)
# make a tempfile for the args and stuff the args into the file
argsfd,argsfile = tempfile.mkstemp()
argsfo = os.fdopen(argsfd, 'w')
argsfo.write(args)
argsfo.flush()
argsfo.close()
args_rem = tmp + 'argsfile'
self.remote_log(conn, "args: %s" % args)
self._transfer_file(conn,argsfile, args_rem)
os.unlink(argsfile)
cmd = "%s %s" % (remote_module_path, args_rem)
argsfile = self._transfer_argsfile(conn, tmp, args)
cmd = "%s %s" % (remote_module_path, 'arguments')
result = self._exec_command(conn, cmd)
return result

@ -31,7 +31,13 @@ except ImportError:
# load config & template variables
input_data = sys.argv[1:]
if len(sys.argv) == 1:
sys.exit(1)
argfile = sys.argv[1]
if not os.path.exists(argfile):
sys.exit(1)
input_data = open(argfile, 'r').read()
new_options = dict([ x.split('=') for x in input_data ])
ansible_file = new_options.get('metadata', DEFAULT_ANSIBLE_SETUP)
ansible_dir = os.path.dirname(ansible_file)

Loading…
Cancel
Save