# Routines to create the administrator account
# @see https://chatgpt.com/share/67b9b12c-064c-800f-9354-8e42e6459764 

- name: Remove line containing "- administrator" from config/settings.yml to allow creating administrator account
  command: 
    cmd:  "docker compose exec -u root web sed -i '/- administrator/d' config/settings.yml"
    chdir: "{{docker_compose.directories.instance}}"
  when: users.administrator.username == "administrator"

- name: Create admin account via tootctl
  command: 
    cmd: 'docker compose exec -u root web bash -c "RAILS_ENV=production bin/tootctl accounts create {{users.administrator.username}} --email {{users.administrator.email}} --confirmed --role Owner"'
    chdir: "{{docker_compose.directories.instance}}"
  ignore_errors: true

- name: Approve the administrator account in Mastodon
  command: 
    cmd: docker compose exec -u root web bash -c "RAILS_ENV=production bin/tootctl accounts modify {{users.administrator.username}} --approve"
    chdir: "{{docker_compose.directories.instance}}"