Move templating into a utils function. Reuse is our friend.

This commit is contained in:
Michael DeHaan 2012-03-19 19:23:14 -04:00
commit af9596307d
3 changed files with 17 additions and 11 deletions

View file

@ -20,13 +20,15 @@
import sys
import os
import shlex
from ansible import errors
import jinja2
try:
import json
except ImportError:
import simplejson as json
from ansible import errors
###############################################################
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
###############################################################
@ -222,4 +224,15 @@ def parse_json(data):
return { "failed" : True, "parsed" : False, "msg" : data }
return results
def template(text, vars):
''' run a text buffer through the templating engine '''
template = jinja2.Template(text)
return template.render(vars)
def template_from_file(path, vars):
''' run a file through the templating engine '''
data = file(path).read()
return template(data, vars)