diff --git a/ingredients/group/groupPresent.go b/ingredients/group/groupPresent.go index 4562865..b76b6ec 100644 --- a/ingredients/group/groupPresent.go +++ b/ingredients/group/groupPresent.go @@ -47,7 +47,7 @@ func (g Group) present(ctx context.Context, test bool) (types.Result, error) { result.Changed = true return result, nil } - if groupByName.Gid != gid { + if groupByName == nil || groupByName.Gid != gid { cmd := exec.CommandContext(ctx, "groupmod", args...) if test { result.Succeeded = true diff --git a/ingredients/user/userPresent.go b/ingredients/user/userPresent.go index aa1d53a..ffeb83d 100644 --- a/ingredients/user/userPresent.go +++ b/ingredients/user/userPresent.go @@ -47,10 +47,10 @@ func (u User) present(ctx context.Context, test bool) (types.Result, error) { userCmd = "useradd" } args := []string{userName} - if uid != "" && uid != user.Uid { + if uid != "" && user == nil || uid != user.Uid { args = append(args, "-u"+uid) } - if gid != "" && gid != user.Gid { + if gid != "" && user == nil || gid != user.Gid { args = append(args, "-g"+gid) } if shell != "" { @@ -72,7 +72,6 @@ func (u User) present(ctx context.Context, test bool) (types.Result, error) { return result, nil } err = cmd.Run() - if err != nil { result.Failed = true result.Succeeded = false diff --git a/testing/recipes/userCreation.grlx b/testing/recipes/userCreation.grlx new file mode 100644 index 0000000..c75bbc8 --- /dev/null +++ b/testing/recipes/userCreation.grlx @@ -0,0 +1,11 @@ +steps: + create void user: + user.present: + - name: void + - uid: "1000" + - gid: "100" + - home: /home/void + - shell: /usr/bin/zsh + - groups: + - wheel + - docker