| 1 |
--- |
| 2 |
- name: Create new admin |
| 3 |
community.grafana.grafana_user: |
| 4 |
name: Harley Quinn |
| 5 |
email: [email protected] |
| 6 |
login: harley |
| 7 |
password: Wy3ta6ob6M3wHELv58MPfqOe126RTnWpcYfEhyJm |
| 8 |
is_admin: true |
| 9 |
state: present |
| 10 |
register: result |
| 11 |
- ansible.builtin.assert: |
| 12 |
that: |
| 13 |
- result.changed == true |
| 14 |
- result.failed == false |
| 15 |
- result.user.name == 'Harley Quinn' |
| 16 |
- result.user.email == '[email protected]' |
| 17 |
- result.user.isGrafanaAdmin == true |
| 18 |
when: not ansible_check_mode |
| 19 |
|
| 20 |
- name: Check idempotency on admin creation |
| 21 |
community.grafana.grafana_user: |
| 22 |
name: Harley Quinn |
| 23 |
email: [email protected] |
| 24 |
login: harley |
| 25 |
password: Wy3ta6ob6M3wHELv58MPfqOe126RTnWpcYfEhyJm |
| 26 |
is_admin: true |
| 27 |
state: present |
| 28 |
register: result |
| 29 |
- ansible.builtin.assert: |
| 30 |
that: |
| 31 |
- result.changed == false |
| 32 |
- result.user.name == 'Harley Quinn' |
| 33 |
- result.user.email == '[email protected]' |
| 34 |
- result.user.isGrafanaAdmin == true |
| 35 |
when: not ansible_check_mode |
| 36 |
|
| 37 |
- name: Check user creation with Grafana API |
| 38 |
ansible.builtin.uri: |
| 39 |
url: "{{ grafana_url }}api/users/lookup?loginOrEmail=harley" |
| 40 |
user: "{{ grafana_username }}" |
| 41 |
password: "{{ grafana_password }}" |
| 42 |
force_basic_auth: true |
| 43 |
status_code: 200 |
| 44 |
headers: |
| 45 |
Accept: application/json |
| 46 |
Content-Type: application/json |
| 47 |
register: result |
| 48 |
- ansible.builtin.assert: |
| 49 |
that: |
| 50 |
- result.json.name == 'Harley Quinn' |
| 51 |
- result.json.email == '[email protected]' |
| 52 |
- result.json.isGrafanaAdmin == true |
| 53 |
when: not ansible_check_mode |
| 54 |
|
| 55 |
- name: Create a Grafana user without password (expect failure) |
| 56 |
community.grafana.grafana_user: |
| 57 |
name: Bruce Wayne |
| 58 |
email: [email protected] |
| 59 |
login: batman |
| 60 |
state: present |
| 61 |
register: result |
| 62 |
ignore_errors: true |
| 63 |
- ansible.builtin.assert: |
| 64 |
that: |
| 65 |
- result.changed == false |
| 66 |
- result.failed == true |
| 67 |
- "result.msg == 'missing required arguments: password'" |
| 68 |
when: not ansible_check_mode |
| 69 |
|
| 70 |
- name: Create a Grafana user |
| 71 |
community.grafana.grafana_user: |
| 72 |
name: Bruce Wayne |
| 73 |
email: [email protected] |
| 74 |
login: batman |
| 75 |
password: robin |
| 76 |
state: present |
| 77 |
register: result |
| 78 |
- ansible.builtin.assert: |
| 79 |
that: |
| 80 |
- result.changed == true |
| 81 |
- result.user.name == 'Bruce Wayne' |
| 82 |
- result.user.email == '[email protected]' |
| 83 |
- result.user.isGrafanaAdmin == false |
| 84 |
when: not ansible_check_mode |
| 85 |
|
| 86 |
- name: Check idempotency on user creation (password not requiered) |
| 87 |
community.grafana.grafana_user: |
| 88 |
name: Bruce Wayne |
| 89 |
email: [email protected] |
| 90 |
login: batman |
| 91 |
state: present |
| 92 |
register: result |
| 93 |
- ansible.builtin.assert: |
| 94 |
that: |
| 95 |
- result.changed == false |
| 96 |
- result.user.name == 'Bruce Wayne' |
| 97 |
- result.user.email == '[email protected]' |
| 98 |
- result.user.isGrafanaAdmin == false |
| 99 |
when: not ansible_check_mode |
| 100 |
|
| 101 |
- name: Check user creation with Grafana API |
| 102 |
ansible.builtin.uri: |
| 103 |
url: "{{ grafana_url }}api/users/lookup?loginOrEmail=batman" |
| 104 |
user: "{{ grafana_username }}" |
| 105 |
password: "{{ grafana_password }}" |
| 106 |
force_basic_auth: true |
| 107 |
status_code: 200 |
| 108 |
headers: |
| 109 |
Accept: application/json |
| 110 |
Content-Type: application/json |
| 111 |
register: result |
| 112 |
- ansible.builtin.assert: |
| 113 |
that: |
| 114 |
- result.json.name == 'Bruce Wayne' |
| 115 |
- result.json.email == '[email protected]' |
| 116 |
- result.json.isGrafanaAdmin == false |
| 117 |
when: not ansible_check_mode |
| 118 |
|
| 119 |
- name: Update Grafana user |
| 120 |
community.grafana.grafana_user: |
| 121 |
name: The Dark Knight |
| 122 |
email: [email protected] |
| 123 |
login: batman |
| 124 |
password: robin |
| 125 |
is_admin: true |
| 126 |
state: present |
| 127 |
register: result |
| 128 |
- ansible.builtin.assert: |
| 129 |
that: |
| 130 |
- result.changed == true |
| 131 |
- result.user.name == 'The Dark Knight' |
| 132 |
- result.user.email == '[email protected]' |
| 133 |
- result.user.isGrafanaAdmin == true |
| 134 |
when: not ansible_check_mode |
| 135 |
|
| 136 |
- name: Check user update with Grafana API |
| 137 |
ansible.builtin.uri: |
| 138 |
url: "{{ grafana_url }}api/users/lookup?loginOrEmail=batman" |
| 139 |
user: "{{ grafana_username }}" |
| 140 |
password: "{{ grafana_password }}" |
| 141 |
force_basic_auth: true |
| 142 |
status_code: 200 |
| 143 |
headers: |
| 144 |
Accept: application/json |
| 145 |
Content-Type: application/json |
| 146 |
register: result |
| 147 |
- ansible.builtin.assert: |
| 148 |
that: |
| 149 |
- result.json.name == 'The Dark Knight' |
| 150 |
- result.json.email == '[email protected]' |
| 151 |
- result.json.isGrafanaAdmin == true |
| 152 |
when: not ansible_check_mode |
| 153 |
|
| 154 |
- name: Delete a Grafana user |
| 155 |
community.grafana.grafana_user: |
| 156 |
login: batman |
| 157 |
state: absent |
| 158 |
register: result |
| 159 |
- ansible.builtin.assert: |
| 160 |
that: |
| 161 |
- result.changed == true |
| 162 |
- result.message == 'User deleted' |
| 163 |
when: not ansible_check_mode |
| 164 |
|
| 165 |
- name: Check idempotency on user deletion |
| 166 |
community.grafana.grafana_user: |
| 167 |
login: batman |
| 168 |
state: absent |
| 169 |
register: result |
| 170 |
- ansible.builtin.assert: |
| 171 |
that: |
| 172 |
- result.changed == false |
| 173 |
- result.message == 'No user found, nothing to do' |
| 174 |
when: not ansible_check_mode |
| 175 |
|
| 176 |
- name: Check user deletion with Grafana API (expect 404 Not Found) |
| 177 |
ansible.builtin.uri: |
| 178 |
url: "{{ grafana_url }}api/users/lookup?loginOrEmail=batman" |
| 179 |
user: "{{ grafana_username }}" |
| 180 |
password: "{{ grafana_password }}" |
| 181 |
force_basic_auth: true |
| 182 |
status_code: 404 |
| 183 |
headers: |
| 184 |
Accept: application/json |
| 185 |
Content-Type: application/json |
| 186 |
register: result |
| 187 |
- ansible.builtin.assert: |
| 188 |
that: |
| 189 |
- result.json.message | lower == 'user not found' |
| 190 |
when: not ansible_check_mode |
| 191 |
|
| 192 |
- name: Create a Grafana user with character encoding |
| 193 |
community.grafana.grafana_user: |
| 194 |
name: Bruce Wayne |
| 195 |
email: [email protected] |
| 196 |
login: [email protected] |
| 197 |
password: robin |
| 198 |
state: present |
| 199 |
register: result |
| 200 |
- ansible.builtin.assert: |
| 201 |
that: |
| 202 |
- result.changed == true |
| 203 |
- result.user.name == 'Bruce Wayne' |
| 204 |
- result.user.email == '[email protected]' |
| 205 |
- result.user.isGrafanaAdmin == false |
| 206 |
when: not ansible_check_mode |
| 207 |
|
| 208 |
- name: Check idempotency on user creation (password not requiered) |
| 209 |
community.grafana.grafana_user: |
| 210 |
name: Bruce Wayne |
| 211 |
email: [email protected] |
| 212 |
login: [email protected] |
| 213 |
state: present |
| 214 |
register: result |
| 215 |
- ansible.builtin.assert: |
| 216 |
that: |
| 217 |
- result.changed == false |
| 218 |
- result.user.name == 'Bruce Wayne' |
| 219 |
- result.user.email == '[email protected]' |
| 220 |
- result.user.isGrafanaAdmin == false |
| 221 |
when: not ansible_check_mode |