feat(ansible): accept string numeric args in wait_for
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
75bafd10c8
commit
afa8efbdbf
2 changed files with 20 additions and 8 deletions
10
modules.go
10
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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue