grafana-ansible-collection/roles/grafana/tasks/preflight.yml

85 lines
3.9 KiB
YAML
Raw Normal View History

---
- name: "Check variable types"
ansible.builtin.assert:
that:
- "grafana_server is mapping"
- "grafana_database is mapping"
- "grafana_security is mapping"
- name: "Fail when datasources aren't configured when dashboards are set to be installed"
ansible.builtin.fail:
msg: "You need to specify datasources for dashboards!!!"
when: "grafana_dashboards != [] and grafana_datasources == []"
- name: "Fail when grafana admin user isn't set"
ansible.builtin.fail:
msg: "Please specify grafana admin user (grafana_security.admin_user)"
when:
- "grafana_security.admin_user == '' or
grafana_security.admin_user is not defined"
- name: "Fail when grafana admin password isn't set"
ansible.builtin.fail:
msg: "Please specify grafana admin password (grafana_security.admin_password)"
when:
- "grafana_security.admin_password == '' or
grafana_security.admin_password is not defined"
- name: "Fail on incorrect variable types in datasource definitions"
ansible.builtin.fail:
msg: "Boolean variables in grafana_datasources shouldn't be passed as strings. Please remove unneeded apostrophes."
when: "( item.isDefault is defined and item.isDefault is string ) or
( item.basicAuth is defined and item.basicAuth is string )"
loop: "{{ grafana_datasources }}"
- name: "Fail on bad database configuration"
ansible.builtin.fail:
msg: "Wrong database configuration. Please look at http://docs.grafana.org/installation/configuration/#database"
when: "( grafana_database.type == 'sqlite3' and grafana_database.url is defined ) or
( grafana_database.type != 'sqlite3' and grafana_database.path is defined ) or
( grafana_database.type == 'sqlite3' and grafana_database.host is defined ) or
( grafana_database.type == 'sqlite3' and grafana_database.user is defined ) or
( grafana_database.type == 'sqlite3' and grafana_database.password is defined ) or
( grafana_database.type == 'sqlite3' and grafana_database.server_cert_name is defined )"
- name: "Fail when grafana domain isn't properly configured"
ansible.builtin.fail:
msg: "Check server configuration. Please look at http://docs.grafana.org/installation/configuration/#server"
when:
- "grafana_server.root_url is defined"
- "grafana_server.root_url is search(grafana_server.domain)"
- name: "Fail when grafana_api_keys uses invalid role names"
ansible.builtin.fail:
msg: "Check grafana_api_keys. The role can only be one of the following values: Viewer, Editor or Admin."
when: "item.role not in ['Viewer', 'Editor', 'Admin']"
loop: "{{ grafana_api_keys }}"
- name: "Fail when grafana_ldap isn't set when grafana_auth.ldap is"
ansible.builtin.fail:
msg: "You need to configure grafana_ldap.servers and grafana_ldap.group_mappings when grafana_auth.ldap is set"
when:
- "'ldap' in grafana_auth"
- "grafana_ldap is not defined or ('servers' not in grafana_ldap or 'group_mappings' not in grafana_ldap)"
- name: "Force grafana_use_provisioning to false if grafana_version is < 5.0 ( grafana_version is set to '{{ grafana_version }}' )"
ansible.builtin.set_fact:
grafana_use_provisioning: false
when:
- "grafana_version != 'latest'"
- "grafana_version is version_compare('5.0', '<')"
- name: "Fail if grafana_port is lower than 1024 and grafana_cap_net_bind_service is not true"
ansible.builtin.fail:
msg: "Trying to use a port lower than 1024 without setting grafana_cap_net_bind_service."
when:
- "grafana_port | int <= 1024"
- "not grafana_cap_net_bind_service"
- name: "Fail if grafana_server.socket not defined when in socket mode"
ansible.builtin.fail:
msg: "You need to configure grafana_server.socket when grafana_server.protocol is set to 'socket'"
when:
- "grafana_server.protocol is defined and grafana_server.protocol == 'socket'"
- "grafana_server.socket is undefined or grafana_server.socket == ''"