feat(ansible): recurse file module group and mode
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
1e5bdc08dd
commit
821211e671
3 changed files with 31 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue