126c45e646
Signed-off-by: gardar <gardar@users.noreply.github.com>
44 lines
1.5 KiB
YAML
44 lines
1.5 KiB
YAML
---
|
|
- name: "Ensure grafana key directory exists"
|
|
ansible.builtin.file:
|
|
path: "{{ grafana_api_keys_dir }}/{{ inventory_hostname }}"
|
|
state: directory
|
|
mode: "0755"
|
|
become: false
|
|
delegate_to: localhost
|
|
|
|
- name: "Check api key list"
|
|
ansible.builtin.uri:
|
|
url: "{{ grafana_api_url }}/api/auth/keys"
|
|
user: "{{ grafana_security.admin_user }}"
|
|
password: "{{ grafana_security.admin_password }}"
|
|
force_basic_auth: true
|
|
return_content: true
|
|
register: __existing_api_keys
|
|
no_log: "{{ 'false' if lookup('env', 'CI') else 'true' }}"
|
|
|
|
- name: "Create grafana api keys"
|
|
ansible.builtin.uri:
|
|
url: "{{ grafana_api_url }}/api/auth/keys"
|
|
user: "{{ grafana_security.admin_user }}"
|
|
password: "{{ grafana_security.admin_password }}"
|
|
force_basic_auth: true
|
|
method: POST
|
|
body_format: json
|
|
body: "{{ item | to_json }}"
|
|
loop: "{{ grafana_api_keys }}"
|
|
register: __new_api_keys
|
|
no_log: "{{ 'false' if lookup('env', 'CI') else 'true' }}"
|
|
when: "((__existing_api_keys['json'] | selectattr('name', 'equalto', item['name'])) | list) | length == 0"
|
|
|
|
- name: "Create api keys file to allow the keys to be seen and used by other automation"
|
|
ansible.builtin.copy:
|
|
dest: "{{ grafana_api_keys_dir }}/{{ inventory_hostname }}/{{ item['item']['name'] }}.key"
|
|
content: "{{ item['json']['key'] }}"
|
|
backup: false
|
|
mode: "0644"
|
|
loop: "{{ __new_api_keys['results'] }}"
|
|
become: false
|
|
delegate_to: localhost
|
|
when: "item['json'] is defined"
|