summaryrefslogtreecommitdiff
path: root/roles/monitoring/grafana/tasks/users.yml
blob: 42159b2e2675e3e1775c2108daa0f9942efc2909 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
---
- name: check if admin password is already set
  check_mode: no
  uri:
    url: "{{ grafana_root_url | resolve_grafana_url(grafana_config_server) }}/api/user"
    user: admin
    password: "{{ grafana_admin_password }}"
    force_basic_auth: true
    body_format: json
    status_code:
    - 200
    - 400
    - 401
  register: grafana_admin_user_info
  until: grafana_admin_user_info is not failed
  retries: 5
  delay: 2

- name: set password for admin user
  when: grafana_admin_user_info.status != 200
  command: grafana-cli admin reset-admin-password --password-from-stdin
  args:
    stdin: "{{ grafana_admin_password }}"
    stdin_add_newline: false

- name: add additional users to grafana
  loop: "{{ grafana_users | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  community.grafana.grafana_user:
    url: "{{ grafana_root_url | resolve_grafana_url(grafana_config_server) }}"
    url_username: admin
    url_password: "{{ grafana_admin_password }}"
    name: "{{ item.value.name | default(omit) }}"
    email: "{{ item.value.email | default(omit) }}"
    login: "{{ item.key }}"
    password: "{{ item.value.password }}"
    is_admin: "{{ item.value.is_admin | default(False) }}"
    state: present