Allow including files through variables

$FILE{file} will be replaced with the contents of "file"
$PIPE{cat file} will be replaced with the output of "cat file"
This commit is contained in:
Daniel Hokka Zakrisson 2012-09-17 14:02:30 +02:00
parent b8c4bb9e6e
commit cc948f339c
9 changed files with 79 additions and 29 deletions

View file

@ -16,7 +16,7 @@ class TestUtils(unittest.TestCase):
}
}
res = ansible.utils._varLookup('data.who', vars)
res = ansible.utils.varLookup('${data.who}', vars)
assert sorted(res) == sorted(vars['data']['who'])
@ -209,10 +209,24 @@ class TestUtils(unittest.TestCase):
'person': 'one',
}
res = ansible.utils.template(template, vars)
res = ansible.utils.template(None, template, vars)
assert res == u'hello oh great one'
def test_varReplace_include(self):
template = 'hello $FILE{world}'
res = ansible.utils.template("test", template, {})
assert res == u'hello world\n'
def test_varReplace_include_script(self):
template = 'hello $PIPE{echo world}'
res = ansible.utils.template("test", template, {})
assert res == u'hello world\n'
#####################################
### Template function tests