Expose check and diff mode magic vars
This commit is contained in:
parent
dac108cab5
commit
cffc35a973
2 changed files with 13 additions and 0 deletions
|
|
@ -286,6 +286,8 @@ func (e *Executor) hostMagicVars(host string) map[string]any {
|
|||
}
|
||||
}
|
||||
if e != nil {
|
||||
values["ansible_check_mode"] = e.CheckMode
|
||||
values["ansible_diff_mode"] = e.Diff
|
||||
if facts := e.hostFactsMap(host); len(facts) > 0 {
|
||||
values["ansible_facts"] = facts
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1278,6 +1278,17 @@ all:
|
|||
assert.Equal(t, inventoryPath+"|"+dir, result)
|
||||
}
|
||||
|
||||
func TestExecutor_Templating_Good_ExposesModeMagicVars(t *testing.T) {
|
||||
e := NewExecutor("/tmp")
|
||||
e.CheckMode = true
|
||||
e.Diff = true
|
||||
|
||||
result := e.templateString("{{ ansible_check_mode }}|{{ ansible_diff_mode }}", "localhost", nil)
|
||||
|
||||
assert.Equal(t, "true|true", result)
|
||||
assert.True(t, e.evalCondition("ansible_check_mode and ansible_diff_mode", "localhost"))
|
||||
}
|
||||
|
||||
func TestExecutor_RunPlay_Good_ExposesRoleContextVars(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, writeTestFile(joinPath(dir, "roles", "demo", "tasks", "main.yml"), []byte(`---
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue