Expose check and diff mode magic vars
Some checks are pending
CI / test (push) Waiting to run
CI / auto-fix (push) Waiting to run
CI / auto-merge (push) Waiting to run

This commit is contained in:
Virgil 2026-04-03 13:26:38 +00:00
parent dac108cab5
commit cffc35a973
2 changed files with 13 additions and 0 deletions

View file

@ -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
}

View file

@ -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(`---