From f728e8c5367418cdc8bd1e772e00936c14eded5d Mon Sep 17 00:00:00 2001 From: Jeroen Hoekx Date: Wed, 4 Apr 2012 13:38:21 +0200 Subject: [PATCH] Introduce per task variables and push them to templates. --- template | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/template b/template index 3421f497ccc..0b13422d5ab 100755 --- a/template +++ b/template @@ -48,7 +48,7 @@ for x in items: source = params['src'] dest = params['dest'] metadata = params.get('metadata', '/etc/ansible/setup') - +module_vars = params.get('vars') # raise an error if there is no template metadata if not os.path.exists(metadata): @@ -71,6 +71,19 @@ except: }) sys.exit(1) +if module_vars: + try: + f = open(module_vars) + vars = json.loads(f.read()) + data.update(vars) + f.close() + except: + print json.dumps({ + "failed" : 1, + "msg" : "Failed to parse/load %s." % module_vars + }) + sys.exit(1) + if not os.path.exists(source): print json.dumps({ "failed" : 1,