1
1
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_gitea.git synced 2024-08-16 11:39:50 +02:00
ansible_role_gitea/tasks/local_git_users.yml

36 lines
1.5 KiB
YAML

---
- name: Identify gitea users
ansible.builtin.command: su - {{ gitea_user }} -c '{{ gitea_full_executable_path }} -c {{ gitea_configuration_path }}/gitea.ini admin user list'
become: true
register: _giteausers
changed_when: false
- name: Use gitea cli to create user
become: true
ansible.builtin.command: |
su - {{ gitea_user }} -c \
'{{ gitea_full_executable_path }} -c {{ gitea_configuration_path }}/gitea.ini \
admin user create --username "{{ item.name }}" \
--password "{{ item.password }}" --email "{{ item.email }}" \
--must-change-password={{ item.must_change_password }} --admin={{ item.admin }}'
register: _gitearesult
failed_when:
- '"successfully created" not in _gitearesult.stdout'
changed_when:
- '"successfully created!" in _gitearesult.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 }}"