mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
Move templating into a utils function. Reuse is our friend.
This commit is contained in:
parent
c1fe0dd719
commit
af9596307d
3 changed files with 17 additions and 11 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue