Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to delete local git user #162

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,17 @@ As this will only deploy config files, fail2ban already has to be installed or o
| `gitea_fail2ban_jail_bantime` | `900` | fail2ban jail `bantime` setting. |
| `gitea_fail2ban_jail_action` | `iptables-allports` | fail2ban jail `action` setting. |

### local gitea Users
| variable | option | description |
| -------- | ------ | ----------- |
| ``gitea_users`` | | dict to create local gitea or forgejo users |
| | ``name`` | name for local gitea/forgejo user |
| | ``password`` | user for local git user |
| | ``email`` | email for local git user |
| | ``admin`` | give user admin permissions |
| | ``must_change_password`` | user should change password after first login |
| | ``state`` | set to ``absent`` to delete user |

### optional customisation
You can optionally customize your gitea using this ansible role. We got our information about customisation from [docs.gitea.io/en-us/customizing-gitea](https://docs.gitea.io/en-us/customizing-gitea/).
To deploy multiple files we created the ``gitea_custom_search`` variable, that can point to the path where you put the custom gitea files *( default ``"files/host_files/{{ inventory_hostname }}/gitea"``)*.
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ gitea_users: []
# email: "[email protected]"
# admin: false
# must_change_password: true
# state: present

# Overall (DEFAULT)
# -> https://docs.gitea.io/en-us/config-cheat-sheet/#overall-default
Expand Down
15 changes: 13 additions & 2 deletions tasks/directory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
state: directory
owner: "{{ gitea_user }}"
group: "{{ gitea_group }}"
mode: "u=rwX,g=rX,o="
mode: "u=rwX,g=rX"
recurse: true
loop:
- "{{ gitea_configuration_path }}"
- "{{ gitea_user_home }}"
- "{{ gitea_home }}"
- "{{ gitea_home }}/data"
Expand All @@ -19,3 +18,15 @@
- "{{ gitea_home }}/indexers"
- "{{ gitea_home }}/log"
- "{{ gitea_repository_root }}"

- name: "Create config and data directory"
become: true
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ gitea_user }}"
group: "{{ gitea_group }}"
mode: "u=rwX,g=rX,o="
recurse: true
loop:
- "{{ gitea_configuration_path }}"
16 changes: 15 additions & 1 deletion tasks/local_git_users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,19 @@
- '"successfully created" not in _gitearesult.stdout'
changed_when:
- '"successfully created!" in _gitearesult.stdout'
when: "_giteausers is defined and item.name not in _giteausers.stdout"
when: "_giteausers is defined and item.name not in _giteausers.stdout and item.state | default('present') == 'present'"
loop: "{{ gitea_users }}"

- name: Use gitea cli to delete user
become: true
ansible.builtin.command: |
su - {{ gitea_user }} -c \
'{{ gitea_full_executable_path }} -c {{ gitea_configuration_path }}/gitea.ini \
admin user delete --username "{{ item.name }}"'
register: _giteadelresult
failed_when:
- '"error" in _giteadelresult.stdout'
changed_when:
"_giteausers is defined and item.name in _giteausers.stdout"
when: "_giteausers is defined and item.name in _giteausers.stdout and item.state | default('present') == 'absent'"
loop: "{{ gitea_users }}"
2 changes: 1 addition & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ transfer_custom_footer:
- 'files/gitea_footer/extra_links_footer.tmpl'
- 'files/extra_links_footer.tmpl'

playbook_version_number: 58
playbook_version_number: 59
playbook_version_path: 'do1jlr.gitea.version'