Skip to content

Commit

Permalink
Create option to delete local git user
Browse files Browse the repository at this point in the history
  • Loading branch information
DO1JLR committed Apr 7, 2024
1 parent f5aaa88 commit 9de9725
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
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 }}"

0 comments on commit 9de9725

Please sign in to comment.