Added stub for template execution, WIP.

This commit is contained in:
Michael DeHaan 2012-02-24 03:45:36 -05:00
parent 102385e4ad
commit 5d6b0280d5
3 changed files with 27 additions and 2 deletions

View file

@ -4,6 +4,10 @@
- configure template & module variables
- setup
- [ "a=2", "b=3", "c=4" ]
- do:
- template from local file template.j2 to remote location /srv/file.out
- template
- [ '/srv/template.j2', '/srv/file.out' ]
- do:
- update apache
- command

View file

@ -111,7 +111,7 @@ class Runner(object):
if not ok:
return [ host, False, conn ]
if self.module_name != "copy":
if self.module_name not in [ 'copy', 'template' ]:
# transfer a module, set it executable, and run it
outpath = self._copy_module(conn)
self._exec_command(conn, "chmod +x %s" % outpath)
@ -120,7 +120,7 @@ class Runner(object):
self._exec_command(conn, "rm -f %s" % outpath)
conn.close()
return [ host, True, json.loads(result) ]
else:
elif self.module_name == 'copy':
# SFTP file copy module is not really a module
self.remote_log(conn, 'COPY remote:%s local:%s' % (self.module_args[0], self.module_args[1]))
ftp = conn.open_sftp()
@ -128,6 +128,24 @@ class Runner(object):
ftp.close()
conn.close()
return [ host, True, 1 ]
elif self.module_name == 'template':
# template runs COPY then the template module
# TODO: DRY/refactor these
# TODO: things like _copy_module should take the name as a param
tempname = os.path.split(self.module_args[0])[-1]
temppath = self._get_tmp_path(conn, tempname)
self.remote_log(conn, 'COPY remote:%s local:%s' % (self.module_args[0], temppath))
ftp = conn.open_sftp()
ftp.put(self.module_args[0], temppath)
ftp.close()
self.module_name = 'template'
self.module_args = [ self.module_args[0], temppath ]
outpath = self._copy_module(conn)
self._exec_command(conn, "chmod +x %s" % outpath)
result = self._exec_command(conn, self._command(outpath))
self._exec_command(conn, "rm -f %s" % outpath)
conn.close()
return [ host, True, json.loads(result) ]
def _command(self, outpath):

3
library/template Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/python
print {}