diff --git a/modules.go b/modules.go index 75cdec8..9c263b7 100644 --- a/modules.go +++ b/modules.go @@ -1812,20 +1812,14 @@ func findInventoryHost(group *InventoryGroup, name string) *Host { } func (e *Executor) moduleWaitFor(ctx context.Context, client sshExecutorClient, args map[string]any) (*TaskResult, error) { - port := 0 - if p, ok := args["port"].(int); ok { - port = p - } + port := getIntArg(args, "port", 0) path := getStringArg(args, "path", "") host := getStringArg(args, "host", "127.0.0.1") state := getStringArg(args, "state", "started") searchRegex := getStringArg(args, "search_regex", "") timeoutMsg := getStringArg(args, "msg", "wait_for timed out") delay := getIntArg(args, "delay", 0) - timeout := 300 - if t, ok := args["timeout"].(int); ok { - timeout = t - } + timeout := getIntArg(args, "timeout", 300) var compiledRegex *regexp.Regexp if searchRegex != "" { var err error diff --git a/modules_adv_test.go b/modules_adv_test.go index efd053d..17f7400 100644 --- a/modules_adv_test.go +++ b/modules_adv_test.go @@ -987,6 +987,24 @@ func TestModulesAdv_ModuleWaitFor_Good_WaitsForPortDrained(t *testing.T) { assert.True(t, mock.hasExecuted(`ss -Htan state established`)) } +func TestModulesAdv_ModuleWaitFor_Good_AcceptsStringNumericArgs(t *testing.T) { + e, mock := newTestExecutorWithMock("host1") + mock.expectCommand(`timeout 0 bash -c 'until ! nc -z 127.0.0.1 8080; do sleep 1; done'`, "", "", 0) + + result, err := e.moduleWaitFor(context.Background(), mock, map[string]any{ + "host": "127.0.0.1", + "port": "8080", + "state": "stopped", + "timeout": "0", + }) + + require.NoError(t, err) + assert.NotNil(t, result) + assert.False(t, result.Failed) + assert.False(t, result.Changed) + assert.True(t, mock.hasExecuted(`until ! nc -z 127.0.0.1 8080`)) +} + // --- include_vars module --- func TestModulesAdv_ModuleIncludeVars_Good_LoadSingleFile(t *testing.T) {