diff --git a/executor.go b/executor.go index 40e08fa..e8a5481 100644 --- a/executor.go +++ b/executor.go @@ -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 } diff --git a/executor_test.go b/executor_test.go index 0eab08b..ada2b60 100644 --- a/executor_test.go +++ b/executor_test.go @@ -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(`---