feat(ansible): recurse file module group and mode
Some checks are pending
CI / test (push) Waiting to run
CI / auto-fix (push) Waiting to run
CI / auto-merge (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 14:27:30 +00:00
parent 1e5bdc08dd
commit 821211e671
3 changed files with 31 additions and 0 deletions

View file

@ -871,6 +871,12 @@ func moduleFileWithClient(_ *Executor, client sshFileRunner, args map[string]any
if owner := getStringArg(args, "owner", ""); owner != "" {
_, _, _, _ = client.Run(context.Background(), sprintf("chown -R %s %q", owner, path))
}
if group := getStringArg(args, "group", ""); group != "" {
_, _, _, _ = client.Run(context.Background(), sprintf("chgrp -R %s %q", group, path))
}
if mode := getStringArg(args, "mode", ""); mode != "" {
_, _, _, _ = client.Run(context.Background(), sprintf("chmod -R %s %q", mode, path))
}
}
return &TaskResult{Changed: true}, nil

View file

@ -812,6 +812,12 @@ func (e *Executor) moduleFile(ctx context.Context, client sshExecutorClient, arg
if owner := getStringArg(args, "owner", ""); owner != "" {
_, _, _, _ = client.Run(ctx, sprintf("chown -R %s %q", owner, path))
}
if group := getStringArg(args, "group", ""); group != "" {
_, _, _, _ = client.Run(ctx, sprintf("chgrp -R %s %q", group, path))
}
if mode := getStringArg(args, "mode", ""); mode != "" {
_, _, _, _ = client.Run(ctx, sprintf("chmod -R %s %q", mode, path))
}
}
return &TaskResult{Changed: true}, nil

View file

@ -495,6 +495,25 @@ func TestModulesFile_ModuleFile_Good_RecurseOwner(t *testing.T) {
assert.True(t, mock.hasExecuted(`chown -R www-data "/var/www"`))
}
func TestModulesFile_ModuleFile_Good_RecurseGroupAndMode(t *testing.T) {
e, mock := newTestExecutorWithMock("host1")
result, err := moduleFileWithClient(e, mock, map[string]any{
"path": "/srv/app",
"state": "directory",
"group": "appgroup",
"mode": "0770",
"recurse": true,
})
require.NoError(t, err)
assert.True(t, result.Changed)
assert.True(t, mock.hasExecuted(`chgrp appgroup "/srv/app"`))
assert.True(t, mock.hasExecuted(`chgrp -R appgroup "/srv/app"`))
assert.True(t, mock.hasExecuted(`chmod -R 0770 "/srv/app"`))
}
func TestModulesFile_ModuleFile_Bad_MissingPath(t *testing.T) {
e, mock := newTestExecutorWithMock("host1")