admin create-user command should be idempotent #3039

Closed
opened 2025-11-02 04:58:32 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @xythobuz on GitHub (Mar 11, 2019).

Like other users (eg. in #2324) I'd like to install and configure gitea using ansible.
Thanks to #4948 the database can already be initialized before running gitea for the first time, so a user can be added.

However, I'd like to be able to repeatedly add the same user (resulting in no action), or use the create-user command to make a user admin that wasn't set as admin before. All this could be done with the existing create-user command interface.

Currently I'm getting the error:

CreateUser: user already exists [ ... ]

When calling the command a second time with the same parameters. I'd like it to just pass.
This would greatly ease use of gitea with something like ansible.

Any plans on implementing this? Or hints on how I could do it myself?

Originally created by @xythobuz on GitHub (Mar 11, 2019). Like other users (eg. in #2324) I'd like to install and configure gitea using ansible. Thanks to #4948 the database can already be initialized before running gitea for the first time, so a user can be added. However, I'd like to be able to repeatedly add the same user (resulting in no action), or use the create-user command to make a user admin that wasn't set as admin before. All this could be done with the existing create-user command interface. Currently I'm getting the error: CreateUser: user already exists [ ... ] When calling the command a second time with the same parameters. I'd like it to just pass. This would greatly ease use of gitea with something like ansible. Any plans on implementing this? Or hints on how I could do it myself?
GiteaMirror added the type/enhancementissue/stale labels 2025-11-02 04:58:32 -06:00
Author
Owner

@zeripath commented on GitHub (Mar 11, 2019):

Ok you'd need to add an option here:

https://github.com/go-gitea/gitea/blob/master/cmd/admin.go#L43

Something like --ignore-already-created but more pithy.

Then adjust:

https://github.com/go-gitea/gitea/blob/master/cmd/admin.go#L345

To check if models.IsErrUserAlreadyExist(err) and if the option is set then return if not.

If you actually want to create or update then you should make another command that does that.

@zeripath commented on GitHub (Mar 11, 2019): Ok you'd need to add an option here: https://github.com/go-gitea/gitea/blob/master/cmd/admin.go#L43 Something like `--ignore-already-created` but more pithy. Then adjust: https://github.com/go-gitea/gitea/blob/master/cmd/admin.go#L345 To check if `models.IsErrUserAlreadyExist(err)` and if the option is set then return if not. If you actually want to create or update then you should make another command that does that.
Author
Owner

@stale[bot] commented on GitHub (Jun 7, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Jun 7, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Jun 21, 2019):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Jun 21, 2019): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3039