From a5561ea2279c60d16497b626fb020bd462f71827 Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Mon, 23 Oct 2023 18:54:21 +0200 Subject: [PATCH] Add creation of admin users --- roles/gotosocial/defaults/main.yml | 11 +++++++++-- roles/gotosocial/tasks/main.yml | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/roles/gotosocial/defaults/main.yml b/roles/gotosocial/defaults/main.yml index 3ea1334..62c9366 100644 --- a/roles/gotosocial/defaults/main.yml +++ b/roles/gotosocial/defaults/main.yml @@ -5,11 +5,18 @@ gotosocial_base_dir: /opt/gotosocial # gotosocial_hostname: gts.example.com -gotosocial_version: "0.12.0-rc2" -gotosocial_release_url: https://github.com/superseriousbusiness/gotosocial/releases/download/v{{ gotosocial_version }}/gotosocial_{{ gotosocial_version }}_linux_amd64.tar.gz +gotosocial_version: "0.12.0" +gotosocial_release_url: | + https://github.com/superseriousbusiness/gotosocial/releases/download/v{{ gotosocial_version }}/gotosocial_{{ gotosocial_version }}_linux_amd64.tar.gz gotosocial_letsencrypt_enabled: false # gotosocial_letsencrypt_email: admin@example.com # required if letsencrypt is enabled # gotosocial_http_port: 80 gotosocial_https_port: 443 + +gotosocial_admin_users: [] +# gotosocial_admin_users: +# - name: username +# - email: example@example.com +# - password: SECRET diff --git a/roles/gotosocial/tasks/main.yml b/roles/gotosocial/tasks/main.yml index cf79dfb..96b404d 100644 --- a/roles/gotosocial/tasks/main.yml +++ b/roles/gotosocial/tasks/main.yml @@ -65,3 +65,26 @@ name: gotosocial.service state: started enabled: true + +- name: Create gotosocial users + ansible.builtin.shell: | + {{ gotosocial_base_dir }}/gotosocial --config-path {{ gotosocial_base_dir }}/config.yaml \ + admin account create --username {{ user.name }} --email {{ user.email }} --password {{ user.password }} > /dev/null + loop: "{{ gotosocial_admin_users | list }}" + register: gotosocial_user_creation + changed_when: gotosocial_user_creation.rc == 0 + failed_when: gotosocial_user_creation.rc != 0 and not 'is already in use' in gotosocial_user_creation.stderr + loop_control: + loop_var: user + label: "{{ user.name }}" + +- name: Set admin rights for gotosocial admin users + ansible.builtin.shell: | + {{ gotosocial_base_dir }}/gotosocial --config-path {{ gotosocial_base_dir }}/config.yaml \ + admin account promote --username {{ user.name }} + loop: "{{ gotosocial_admin_users | list }}" + register: gotosocial_admin_promotion + changed_when: gotosocial_admin_promotion.rc == 0 + loop_control: + loop_var: user + label: "{{ user.name }}"