feat(ansible): add template lookup support
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
bae7fa0a39
commit
3eca6b15cb
2 changed files with 16 additions and 0 deletions
|
|
@ -3612,6 +3612,10 @@ func (e *Executor) lookupValue(expr string, host string, task *Task) (any, bool)
|
|||
if data, err := coreio.Local.Read(e.resolveLocalPath(arg)); err == nil {
|
||||
return data, true
|
||||
}
|
||||
case "template":
|
||||
if data, err := e.TemplateFile(arg, host, task); err == nil {
|
||||
return data, true
|
||||
}
|
||||
case "fileglob":
|
||||
if matches, err := e.resolveFileGlob(arg); err == nil && len(matches) > 0 {
|
||||
return matches, true
|
||||
|
|
|
|||
|
|
@ -879,6 +879,18 @@ func TestExecutorExtra_HandleLookup_Good_FileLookupResolvesBasePath(t *testing.T
|
|||
assert.Equal(t, "from base path", result)
|
||||
}
|
||||
|
||||
func TestExecutorExtra_HandleLookup_Good_TemplateLookupResolvesBasePathAndVars(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, writeTestFile(joinPath(dir, "templates", "message.j2"), []byte("Hello {{ name }}"), 0644))
|
||||
|
||||
e := NewExecutor(dir)
|
||||
e.SetVar("name", "world")
|
||||
|
||||
result := e.handleLookup("lookup('template', 'templates/message.j2')", "host1", nil)
|
||||
|
||||
assert.Equal(t, "Hello world", result)
|
||||
}
|
||||
|
||||
func TestExecutorExtra_HandleLookup_Good_VarsLookup(t *testing.T) {
|
||||
e := NewExecutor("/tmp")
|
||||
e.SetVar("lookup_value", "resolved from vars")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue