diff --git a/ansible/roles/grafana/defaults/main.yml b/ansible/roles/grafana/defaults/main.yml index e0e4fb8b0b..76b9046c7b 100644 --- a/ansible/roles/grafana/defaults/main.yml +++ b/ansible/roles/grafana/defaults/main.yml @@ -23,16 +23,17 @@ grafana_database_address: "{{ kolla_internal_fqdn }}:{{ database_port }}" #################### # Datasource #################### -grafana_data_source: - isDefault: yes - database: "telegraf" - user: admin - password: "{{ grafana_admin_password }}" - name: "telegraf" - type: "influxdb" - url: "{{ internal_protocol }}://{{ api_interface_address }}:{{ influxdb_http_port }}" - access: "proxy" - basicAuth: false +grafana_data_sources: + influxdb: + enabled: "{{ enable_influxdb | bool }}" + data: + isDefault: yes + database: "telegraf" + name: "telegraf" + type: "influxdb" + url: "{{ internal_protocol }}://{{ api_interface_address }}:{{ influxdb_http_port }}" + access: "proxy" + basicAuth: false ########## # Grafana diff --git a/ansible/roles/grafana/tasks/post_config.yml b/ansible/roles/grafana/tasks/post_config.yml index a3615505f0..2acec9db7e 100644 --- a/ansible/roles/grafana/tasks/post_config.yml +++ b/ansible/roles/grafana/tasks/post_config.yml @@ -10,20 +10,21 @@ run_once: true connection: local -- name: Enable influxdb datasource +- name: Enable grafana datasources uri: url: "{{ internal_protocol }}://{{ kolla_internal_vip_address }}:{{ grafana_server_port }}/api/datasources" method: POST user: admin password: "{{ grafana_admin_password }}" - body: "{{ grafana_data_source | to_json }}" + body: "{{ item.value.data | to_json }}" body_format: json force_basic_auth: yes status_code: 200, 409 register: response run_once: True connection: local - when: grafana_data_source is defined changed_when: response.status == 200 failed_when: response.status not in [200, 409] or response.status == 409 and ("Data source with same name already exists" not in response.json.message|default("")) + with_dict: "{{ grafana_data_sources }}" + when: item.value.enabled | bool