feat(ansible): expose ansible_limit magic var
This commit is contained in:
parent
0e3c126723
commit
fd6b8b0d2f
2 changed files with 38 additions and 0 deletions
|
|
@ -442,6 +442,7 @@ func (e *Executor) runPlay(ctx context.Context, play *Play) error {
|
|||
e.vars["ansible_play_name"] = play.Name
|
||||
e.vars["ansible_play_hosts_all"] = append([]string(nil), hosts...)
|
||||
e.vars["ansible_play_hosts"] = append([]string(nil), hosts...)
|
||||
e.vars["ansible_limit"] = e.Limit
|
||||
|
||||
// Merge play vars
|
||||
if err := e.loadPlayVarsFiles(play); err != nil {
|
||||
|
|
|
|||
|
|
@ -814,6 +814,43 @@ func TestExecutorExtra_RunPlay_Good_ExposesPlayMagicVars(t *testing.T) {
|
|||
assert.Equal(t, "Inspect play magic vars|[host1 host2]|[host1 host2]|[host2]", e.results["host2"]["magic_vars"].Msg)
|
||||
}
|
||||
|
||||
func TestExecutorExtra_RunPlay_Good_ExposesLimitMagicVar(t *testing.T) {
|
||||
gatherFacts := false
|
||||
e := NewExecutor(t.TempDir())
|
||||
e.Limit = "host1"
|
||||
e.SetInventoryDirect(&Inventory{
|
||||
All: &InventoryGroup{
|
||||
Hosts: map[string]*Host{
|
||||
"host1": {},
|
||||
"host2": {},
|
||||
},
|
||||
},
|
||||
})
|
||||
e.clients["host1"] = NewMockSSHClient()
|
||||
|
||||
play := &Play{
|
||||
Name: "Inspect limit magic var",
|
||||
Hosts: "all",
|
||||
GatherFacts: &gatherFacts,
|
||||
Tasks: []Task{
|
||||
{
|
||||
Name: "Inspect limit magic var",
|
||||
Module: "debug",
|
||||
Args: map[string]any{
|
||||
"msg": "{{ ansible_limit }}",
|
||||
},
|
||||
Register: "limit_var",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
require.NoError(t, e.runPlay(context.Background(), play))
|
||||
|
||||
require.NotNil(t, e.results["host1"]["limit_var"])
|
||||
assert.Equal(t, "host1", e.results["host1"]["limit_var"].Msg)
|
||||
assert.Nil(t, e.results["host2"])
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Tests for handleLookup (0% coverage)
|
||||
// ============================================================
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue