This code uses Grafana API to add a new users from localhost. Not perfect, but it works.
tasks/main.yml
- name: Include vars
include_vars:
file: main.yml
file: secrets.yml
- name: create users
uri:
url: "https://{{ grafana_fqdn }}/api/admin/users"
user: "admin"
password: "{{ grafana_admin_pwd }}"
force_basic_auth: yes
method: POST
headers:
Accept: application/json
Content-Type: application/json
body:
name: "{{ item.name }}"
email: "{{ item.email }}"
login: "{{ item.email }}"
password: "{{ grafana_default_new_user_pwd }}"
body_format: json
with_items: "{{ grafana_admin_list }}"
delegate_to: localhost
become: no
ignore_errors: yes
vars/main.yml
grafana_fqdn: grafana.domain.tld
grafana_admin_list:
- name: "Dmitri Telinov"
login: "dtelinov"
email: "telinovdima@gmail.com"
- name: "John Doe"
login: "jdoe"
email: "jdoe@gmail.com"
vars/secrets.yml
---
grafana_admin_pwd: "xxx"
grafana_default_new_user_pwd: "yyy"