cloudalchemy.grafana

DEPRECATED

This role is no longer maintained. Please use the grafana-ansible-collection instead.

grafana logo

Ansible Role: grafana

Build Status License Ansible Role GitHub tag

This role helps you install and manage grafana, a tool for data analysis and monitoring.

Requirements

  • Ansible version 2.7 or higher (it might work on older versions, but we can't promise it).
  • The package libselinux-python on the server if SELinux is enabled.
  • Grafana version 5.1 or higher (for older versions, use an earlier version of this role).
  • Install jmespath on the server if using Ansible from a Python virtual environment.

Role Variables

The variables you can change are stored in defaults/main.yml and listed below.

Name Default Value Description
grafana_use_provisioning true Enable Grafana provisioning if possible (grafana_version=latest assumes >= 5.0).
grafana_provisioning_synced false Delete old dashboards that are no longer referenced.
grafana_version latest Grafana version to install
grafana_yum_repo_template etc/yum.repos.d/grafana.repo.j2 Yum repository template path
grafana_manage_repo true Manage package repository
grafana_instance {{ ansible_fqdn default(ansible_host)
grafana_logs_dir /var/log/grafana Path for Grafana logs
grafana_data_dir /var/lib/grafana Path for Grafana database
grafana_address 0.0.0.0 Address where Grafana listens
grafana_port 3000 Port for Grafana
grafana_cap_net_bind_service false Allows using ports below 1024 without root access.
grafana_url "http://{{ grafana_address }}:{{ grafana_port }}" URL to access Grafana in a web browser
grafana_api_url "{{ grafana_url }}" URL for API calls during provisioning (if different).
grafana_domain "{{ ansible_fqdn default(ansible_host)
grafana_server { protocol: http, enforce_domain: false, socket: "", cert_key: "", cert_file: "", enable_gzip: false, static_root_path: public, router_logging: false } Server configuration section
grafana_security { admin_user: admin, admin_password: "" } Security configuration section
grafana_database { type: sqlite3 } Database configuration section
grafana_welcome_email_on_sign_up false Send a welcome email after user registration
grafana_users { allow_sign_up: false, auto_assign_org_role: Viewer, default_theme: dark } Users configuration section
grafana_auth {} Authorization configuration section
grafana_ldap {} LDAP configuration section.
grafana_session {} Session management configuration section
grafana_analytics {} Google Analytics configuration section
grafana_smtp {} SMTP configuration section
grafana_alerting {} Alerting configuration section
grafana_log {} Logging configuration section
grafana_metrics {} Metrics configuration section
grafana_tracing {} Tracing configuration section
grafana_snapshots {} Snapshots configuration section
grafana_image_storage {} Image storage configuration section
grafana_dashboards [] List of dashboards to import
grafana_dashboards_dir "dashboards" Local directory for dashboards files in JSON format
grafana_datasources [] List of data sources to configure
grafana_environment {} Optional environment parameters for Grafana installation
grafana_plugins [] List of Grafana plugins to install
grafana_alert_notifications [] List of alert notification channels to manage

Datasource Example

grafana_datasources:
  - name: prometheus
    type: prometheus
    access: proxy
    url: 'http://{{ prometheus_web_listen_address }}'
    basicAuth: false

Dashboard Example

grafana_dashboards:
  - dashboard_id: 111
    revision_id: 1
    datasource: prometheus

Alert Notification Channel Example

NOTE: The variable grafana_alert_notifications will only take effect if grafana_use_provisioning is set to true. This enables the provisioning system starting from Grafana version 5.0.

grafana_alert_notifications:
  notifiers:
    - name: Channel 1
      type: email
      uid: channel1
      is_default: false
      send_reminder: false
      settings:
        addresses: "[email protected]"
        autoResolve: true
  delete_notifiers:
    - name: Channel 2
      uid: channel2

Custom Grafana Yum Repo Template Example

  • Place your template in a templates folder next to your playbook.

  • Use a unique path for your template; otherwise, Ansible may use the first template found.

  • The template will be saved to /etc/yum.repos.d/ with the name based on the template's path (without the .j2 suffix).

    Example:

    grafana_yum_repo_template: my_yum_repos/grafana.repo.j2
    
    # Template located at:
    # [playbook_dir]/templates/my_yum_repos/grafana.repo.j2
    # will be saved to:
    # /etc/yum.repos.d/grafana.repo
    

Supported CPU Architectures

Historically, packages were sourced based on CPU architecture. Now, all packages come from the official sources for Debian/Ubuntu or RPM.

Example

Playbook

Set your desired admin password; the Grafana web interface won't prompt for a change at the first login.

- hosts: all
  roles:
    - role: cloudalchemy.grafana
      vars:
        grafana_security:
          admin_user: admin
          admin_password: enter_your_secure_password

Demo Site

A demo site is available showcasing a full monitoring solution using Prometheus and Grafana. You can find the code and links on GitHub and it's hosted on DigitalOcean.

Local Testing

For local testing, it's recommended to use Docker and molecule (version 2.x). You need to install Docker on your machine. To install molecule and test methods, run:

pip3 install tox

Run tests on all Ansible versions (this may take some time):

tox

To run a specific molecule command in a custom environment:

tox -e py35-ansible28 -- molecule test -s default

For more details on molecule, check their documentation.

If you want to run tests on a remote Docker host, set the DOCKER_HOST variable before running tox tests.

Travis CI

Using Molecule alongside Travis CI helps test new PRs across different Ansible versions and operating systems, creating a comprehensive test matrix.

Contributing

Please refer to the contributor guideline.

Troubleshooting

For issues, check the troubleshooting.

License

This project is licensed under the MIT License. More details can be found in the LICENSE.

Informazioni sul progetto

Grafana - platform for analytics and monitoring

Installa
ansible-galaxy install cloudalchemy.grafana
Licenza
mit
Download
1.9M
Proprietario
Setup your monitoring stack with ansible