Coder Social home page Coder Social logo

ansible-collections / community.grafana Goto Github PK

View Code? Open in Web Editor NEW
121.0 10.0 78.0 702 KB

Grafana Collection for Ansible

Home Page: http://galaxy.ansible.com/community/grafana

License: GNU General Public License v3.0

Python 99.54% Shell 0.46%
ansible-collection grafana ansible hacktoberfest

community.grafana's Introduction

Grafana Collection for Ansible

Codecov

All Contributors

This repo hosts the community.grafana Ansible Collection.

The collection includes a variety of Ansible content to help automate the management of resources in Grafana.

Included content

Click on the name of a plugin or module to view that content's documentation:

Supported Grafana versions

We aim at keeping the last 3 Major versions of Grafana tested. This collection is currently testing the modules against following versions of Grafana:

grafana_version: ["8.5.27", "9.5.19", "10.4.3"]

Installation and Usage

Installing the Collection from Ansible Galaxy

Before using the Grafana collection, you need to install it with the Ansible Galaxy CLI:

ansible-galaxy collection install community.grafana

You can also include it in a requirements.yml file and install it via ansible-galaxy collection install -r requirements.yml, using the format:

---
collections:
  - name: community.grafana
    version: 1.3.1

Using modules from the Grafana Collection in your playbooks

You can either call modules by their Fully Qualified Collection Namespace (FQCN), like community.grafana.grafana_datasource, or you can call modules by their short name if you list the community.grafana collection in the playbook's collections, like so:

---
- hosts: localhost
  gather_facts: false
  connection: local

  tasks:
    - name: Ensure Influxdb datasource exists.
      community.grafana.grafana_datasource:
        name: "datasource-influxdb"
        grafana_url: "https://grafana.company.com"
        grafana_user: "admin"
        grafana_password: "xxxxxx"
        org_id: "1"
        ds_type: "influxdb"
        ds_url: "https://influx.company.com:8086"
        database: "telegraf"
        time_interval: ">10s"
        tls_ca_cert: "/etc/ssl/certs/ca.pem"

For documentation on how to use individual modules and other content included in this collection, please see the links in the 'Included content' section earlier in this README.

Using module group defaults

In your playbooks, you can set module defaults for the community.grafana.grafana group to avoid repeating the same parameters (e.g., grafana_url, grafana_user, grafana_password) in your tasks:

---
- hosts: localhost
  gather_facts: false
  connection: local

  module_defaults:
    group/community.grafana.grafana:
      grafana_url: "https://grafana.company.com"
      grafana_user: "admin"
      grafana_password: "xxxxxx"

  tasks:
    - name: Ensure Influxdb datasource exists.
      community.grafana.grafana_datasource:
        name: "datasource-influxdb"
        org_id: "1"
        ds_type: "influxdb"
        ds_url: "https://influx.company.com:8086"
        database: "telegraf"
        time_interval: ">10s"
        tls_ca_cert: "/etc/ssl/certs/ca.pem"
    
    - name: Create or update a Grafana user
      community.grafana.grafana_user:
        name: "Bruce Wayne"
        email: "[email protected]"
        login: "batman"
        password: "robin"
        is_admin: true

Testing and Development

If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured COLLECTIONS_PATHS, and work on it there.

Testing with ansible-test

The tests directory contains configuration for running sanity and integration tests using ansible-test.

You can run the collection's test suites with the commands:

ansible-test sanity --docker -v --color
ansible-test units --docker -v --color
ansible-test integration --docker -v --color

Publishing New Versions

The collection is automatically released on Galaxy when a tag is created on the repository. The release pipeline is managed by the Ansible Team as the collection is part of the community namespace.

The current process for creating a tag is manual.

Changelogs

Abstract from Ansible requirements for Collections:

* Every change that does not only affect docs or tests must have a changelog fragment.
  * Exception: fixing/extending a feature that already has a changelog fragment and has not yet been released. Such PRs must always link to the original PR(s) they update.
  * Use your common sense!
  * (This might change later. The trivial category should then be used to document changes which are not important enough to end up in the text version of the changelog.)
  * Fragments must not be added for new module PRs and new plugin PRs. The only exception are test and filter plugins: these are not automatically documented yet.
* The (x+1).0.0 changelog continues the x.0.0 changelog.
  * A x.y.0 changelog with y > 0 is not part of a changelog of a later X.*.* (with X > x) or x,Y,* (with Y > y) release.
  * A x.y.z changelog with z > 0 is not part of a changelog of a later (x+1).*.* or x.Y.z (with Y > y) release.
Since everything adding to the minor/patch changelogs are backports, the same changelog fragments of these minor/patch releases will be in the next major release's changelog. (This is the same behavior as in ansible/ansible.)
* Changelogs do not contain previous major releases, and only use the ancestor feature (in changelogs/changelog.yaml) to point to the previous major release.
* Changelog fragments are removed after a release is made.

See antsibull-changelog documentation for fragments format.

Generate a new changelog:

  1. Update the collection version in galaxy.yml if required.
  2. Generate the changelog:
$ antsibull-changelog release

License

GNU General Public License v3.0 or later

See LICENCE to see the full text.

Contributing

Any contribution is welcome and we only ask contributors to:

  • Provide at least integration tests for any contribution.
  • The Pull Request MUST contain a changelog fragment. See Ansible documentation about fragments.
  • Create an issue for any significant contribution that would change a large portion of the code base.
  • Use ruff to lint and black to format your changes on python code.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

John R Barker
John R Barker

🚇 ⚠️ 💻
Rémi REY
Rémi REY

⚠️ 📖 💻
Thierry Sallé
Thierry Sallé

💻 ⚠️
Antoine
Antoine

💻 ⚠️
hvle
hvle

💻 ⚠️
jual
jual

💻 ⚠️
MCyprien
MCyprien

💻 ⚠️
Markus Fischbacher
Markus Fischbacher

💻
Remi Verchere
Remi Verchere

💻
Abhijeet Kasurde
Abhijeet Kasurde

📖 ⚠️
martinwangjian
martinwangjian

💻
cwollinger
cwollinger

💻
Andrew Klychkov
Andrew Klychkov

💻
Victor
Victor

💻
paytroff
paytroff

💻 ⚠️
Justin Seiser
Justin Seiser

💻
Pierre
Pierre

🐛
MiksonX
MiksonX

🐛
Aliaksandr Mianzhynski
Aliaksandr Mianzhynski

💻 ⚠️
Moritz
Moritz

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

community.grafana's People

Contributors

allcontributors[bot] avatar amenzhinsky avatar andersson007 avatar benjaminschubert avatar cwollinger avatar fegalo avatar flkhndlr avatar geerlingguy avatar ggiinnoo avatar gundalow avatar hoangphuocbk avatar johndoe12312 avatar ko-christ avatar kongslund avatar lusitaniae avatar michaelamattes avatar nemental avatar nutgood avatar pigay avatar pomverte avatar prndrbr avatar rbnis avatar renovate-bot avatar renovate[bot] avatar rndmh3ro avatar rockaut avatar rrey avatar rrey-aviatrix avatar seuf avatar webknjaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

community.grafana's Issues

Invalid removal version according to semantic versioning

SUMMARY

The commit_message option of grafana_dashboard is depreated with removal version community.grafana 2.14.0. According to semantic versioning, breaking changes in the API can only be made in major versions, while 2.14.0 is a minor release.

I'd suggest you either change 2.14.0 to 2.0.0, or to 3.0.0, depending what your versioning plans are for community.grafana.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_dashboard

Some way to add own/additional jsonData

SUMMARY

Currently there is now way to add some additional/custom jsonData which would be beneficial to handle data needed or wanted by the datasources. Like alerting for zabbix as example. Current provided properties can of course override the given data.

Adding all the additional options as module parameters wouldn't be too handy.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

grafana_datasource

ADDITIONAL INFORMATION
    - community.grafana.grafana_datasource:
        name: "Zabbix"
        ds_type: "alexanderzobnin-zabbix-datasource"
        access: "proxy"
        ds_url: "http://zabbix/api_jsonrpc.php"
        is_default: false
        additional_jsonData:
          addThresholds: false
          alerting: false
          alertingMinSeverity: 3

secureJsonData related properties aren't updated

SUMMARY

Changing any module property like tls_ca_cert doesn't update after first creation of the datasource.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_datasource

ANSIBLE VERSION

2.9, 2.10.0rc#

OS / ENVIRONMENT

Grafana 6.9, 7.1.1

STEPS TO REPRODUCE
    # creates the DS and reports changed=True
    - name: jat ds 2
      delegate_to: localhost
      run_once: true
      grafana_datasource:
        name: justatest2
        ds_type: prometheus
        access: proxy
        ds_url: https://whatever.com
        tls_ca_cert: asdfasdfasdf

    # should change the tls_ca_cert related secureJsonData but doesn't and changed=False
    - name: jat ds 2
      delegate_to: localhost
      run_once: true
      grafana_datasource:
        name: justatest2
        ds_type: prometheus
        access: proxy
        ds_url: https://whatever.com
        tls_ca_cert: jlkjölkjölkjlkjljlkjlkjl
EXPECTED RESULTS

Booth tasks should changed=true

How do you use this?

SUMMARY

How do you use this collection? I noticed there was a discussion in another PR, has this been cleared up? I am happy to send a PR to get this started.

ISSUE TYPE
  • Documentation Report

support module group defaults

SUMMARY

As a user I want avoid repeating same parameters to module tasks in playbooks using module group defaults.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

All components.

ADDITIONAL INFORMATION

I have long list of tasks for datasources, dashboards, users... and I avoid repeating the same parameters by using module defaults.

  collections:
    - community.grafana

  module_defaults:
    grafana_datasource:
      url: "http://localhost:3000"
      url_username: "admin"
      url_password: "foo"
      org_id: "1"
      ds_url: "http://influxdb.localnet:8086"
      user: 'foo'
      password: 'foo'
      time_interval: ">10s"
    grafana_dashboard:
      grafana_url: "http://localhost:3000"
      url_username: "admin"
      url_password: "foo"
      org_id: "1"
    grafana_user:
      grafana_url: "http://localhost:3000"
      url_username: "admin"
      url_password: "foo"

tasks:
    - name: Ensure Influxdb datasource exists.
      grafana_datasource:
        name: "influxdb"
        ds_type: "influxdb"
        database: "sensorit"

    - name: Ensure katkaisimet datasource exists.
      grafana_datasource:
        name: "katkaisimet"
        ds_type: "influxdb"
        database: "katkaisimet"

....

Now if there was group defaults, I could avoid repeating even further, putting all variables under one group which then would apply to all modules at once:

  collections:
    - community.grafana

  module_defaults:
    group/grafana:
      url: "http://localhost:3000"
      url_username: "admin"
      url_password: "foo"

FYI, e.g. k8s modules implement this.

Ansible 2.10.0 and 1.0.0 before 2020-08-18

As im active in the Zabbix Collection we there got the following message from @gundalow :

“The 2020-08-18 date is of particular importance. This means that by that day, you MUST have released 1.0.0 for it to appear in Ansible 2.10. If you only have a 0.x.y release by then, we will not automatically include a newer version since according to semver, anything can happen and no stability guarantees are made. So please make sure that you released 1.0.0 by then.”

Just wanted to drop it here if you haven't heard.

Importing dashboard to a certain folder

SUMMARY

When using grafana_dashboard module, imported dashboard always lands in the main folder. It'd be useful to point a folder (e.g. by providing folder_id), where the dashboard should be imported.

ISSUE TYPE
  • Feature enhancement (importing dashboards)

grafana_dashboard not idempotent

SUMMARY

Running the grafana_dashboard module (with same args) results in changed=True, when no uid is given.

When you create a dashboard without the argument 'uid' grafana will generate one.
This results in changed=True.

A possible solution would be to ignore the uid key in grafana_dashboard_changed() in grafana_dashboard.py

if 'uid' not in payload['dashboard'] and 'uid' in dashboard['dashboard']:
        del(dashboard['dashboard']['uid'])

easyfix: delete unused imports

SUMMARY

Some easy fixes for anyone that wants to take them, basically deleting some unused improts.

plugins/modules/grafana_user.py:164:1: F401 'ansible_collections.community.grafana.plugins.module_utils.base.grafana_mutually_exclusive' imported but unused 
 

===== LINTING MODULE: grafana_plugin ===== 
flake8 Warnings: 
plugins/modules/grafana_plugin.py:75:1: F401 'base64' imported but unused 
plugins/modules/grafana_plugin.py:76:1: F401 'json' imported but unused 
 
===== IMPORTING MODULE: grafana_plugin ===== 
 
===== LOADING MODULE ===== 
 
===== LINTING MODULE: grafana_folder ===== 
flake8 Warnings: 
plugins/modules/grafana_folder.py:264:13: F841 local variable 'new_folder' is assigned to but never used 
 
===== IMPORTING MODULE: grafana_folder ===== 
 
===== LOADING MODULE ===== 
 
===== LINTING MODULE: grafana_dashboard ===== 
flake8 Warnings: 
plugins/modules/grafana_dashboard.py:189:9: F841 local variable 'e' is assigned to but never used 
 
===== LINTING MODULE: grafana_datasource ===== 
flake8 Warnings: 
plugins/modules/grafana_datasource.py:447:1: F401 'base64' imported but unused 
 
===== LINTING MODULE: grafana_team ===== 
flake8 Warnings: 
plugins/modules/grafana_team.py:305:13: F841 local variable 'new_team' is assigned to but never used 
 

===== LINTING CALLBACK_PLUGIN: grafana_annotations ===== 
flake8 Warnings: 
plugins/callback/grafana_annotations.py:20:1: F401 'os' imported but unused 
plugins/callback/grafana_annotations.py:24:1: F401 'base64.b64encode' imported but unused 
plugins/callback/grafana_annotations.py:269:13: F841 local variable 'response' is assigned to but never used 
 

===== LINTING LOOKUP_PLUGIN: grafana_dashboard ===== 
flake8 Warnings: 
plugins/lookup/grafana_dashboard.py:62:1: F401 'base64' imported but unused 
plugins/lookup/grafana_dashboard.py:65:1: F401 'ansible.errors.AnsibleParserError' imported but unused 
plugins/lookup/grafana_dashboard.py:68:1: F401 'ansible.module_utils._text.to_bytes' imported but unused 
 
ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION

CONFIGURATION

OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS

Can't create folder on Grafana 7.3.7 stable (tried 7.1.3 as well, same issue)

SUMMARY

Trying to create "named folders" and upload "named dashboards" to them.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.grafana.grafana_folder

ANSIBLE VERSION
ansible --version
ansible 2.10.5
  config file = /Users/xxx/yada/yada/ansible.cfg
  configured module search path = ['/Users/xxxxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.1 (default, Jan 30 2021, 15:51:59) [Clang 12.0.0 (clang-1200.0.32.29)]
CONFIGURATION

OS / ENVIRONMENT

Ubuntu 20.04
Grafana 7.3.7 stable -- installed from the official Grafana repository (oss stable)

STEPS TO REPRODUCE

Posting the relevant tasks only. All variables work in other tasks. The upload to /tmp/dashboard is omitted here.

- name: "Create {{ pool_ticker }} folder"
  community.grafana.grafana_folder:
    state: present
    name: "{{ pool_ticker }}"
    url: "https://{{ grafana_domain }}"
    url_username: "{{ grafana_admin_user }}"
    url_password: "{{ grafana_admin_pass }}"

- name: "Import {{ pool_ticker }} Metrics v1 Dashboard"
  community.grafana.grafana_dashboard:
    dashboard_revision: "1"
    folder: "{{ pool_ticker }}"
    path: "/tmp/{{ pool_ticker }}-PoolMetricsV1.json"
    grafana_url: "https://{{ grafana_domain }}"
    url_username: "{{ grafana_admin_user }}"
    url_password: "{{ grafana_admin_pass }}"
EXPECTED RESULTS

a folder with a ticker name should be created.
a ticker named dashboard should be uploaded to the above folder.

ACTUAL RESULTS
fatal: [spaas-mon]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 142.93.43.238 closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/home/igghibu/.ansible/tmp/ansible-tmp-1612433673.381998-67602-133808153941091/AnsiballZ_grafana_folder.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/igghibu/.ansible/tmp/ansible-tmp-1612433673.381998-67602-133808153941091/AnsiballZ_grafana_folder.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/igghibu/.ansible/tmp/ansible-tmp-1612433673.381998-67602-133808153941091/AnsiballZ_grafana_folder.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_folder', init_globals=None, run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 274, in <module>\r\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 254, in main\r\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 178, in __init__\r\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_ybp_mas9/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 208, in get_version\r\nAttributeError: 'NoneType' object has no attribute 'split'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Grafana Pinboard

GitHub Grafana issues GitHub Grafana PRs Grafana pinboard

We could collectively benefit from forming a Working Group related to Grafana integration. We have quite some contributors on GitHub and users on IRC that are interested in improving this integration.

So this issue is a call for potential interested parties (earlier and existing contributors to Ansible). The benefits of having a Working Group is that members of the Working Group can:

  • test, review and add shipits to existing Grafana PRs
  • work collectively on the Grafana roadmap
  • provide a single-point-of-contact for interested Grafana contributors
  • collaborate on an Grafana Wiki
  • have a $team_grafana in BOTMETA.yml for auto-notifying team members
  • implement auto-labeling grafana issues and PRs

[3d] Publishing Grafana collection to Galaxy

SUMMARY
  • Versioning
  • Update CI to test from a collection build, rather than git source. ie test closer to how end-users will install the collection

Use job: https://github.com/ansible/ansible-zuul-jobs/blob/master/zuul.d/project-templates.yaml#L1218
Use https://github.com/ansible/project-config/blob/master/zuul.d/projects.yaml

Setup to watch git-tag & PR creation.

Initially, public to galaxy-dev only during testing

Document this so other Community Collections can use it.

Future

  • Create ansible-zuul (bot) account
ISSUE TYPE
  • Feature Idea
COMPONENT NAME
ADDITIONAL INFORMATION

Support for Loki Datasource

SUMMARY

Support for Loki Datasources in grafana_datasource module.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

grafana_datasource

ADDITIONAL INFORMATION

Currently it's not possible to add a loki datasource with the grafana_datasource module in this collection.

It would be nice to add one with a task like this:

- name: Ensure loki datasource exists.
  grafana_datasource:
    name: "datasource-loki"
    grafana_url: "https://grafana.company.com"
    grafana_user: "admin"
    grafana_password: "xxxxxx"
    org_id: "1"
    ds_type: "loki"
    ds_url: "https://loki.company.com:3100"

I took a brief look at the grafana_datasource module and it seems at first glance that it just has to be added here:

ds_type=dict(choices=['graphite',
'prometheus',
'elasticsearch',
'influxdb',
'opentsdb',
'mysql',
'postgres',
'cloudwatch',
'alexanderzobnin-zabbix-datasource',
'sni-thruk-datasource'], required=True),

If so, I can open a PR for this.

Codecov badge is broken

Hi John !

I noticed that the codecov badge is down, I think it comes from the repository rename that happened recently.
I don't have permissions on the codecov side, could you help us ?

grafana_datasource reports 'changed' for repeated runs

SUMMARY

grafana_datasource module reports 'changed' for each run even if nothing has been changed in datasoure.

I'm simply migrating this from ansible/ansible#51068 which wasn't migrated automatically.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_datasource

ANSIBLE VERSION
ansible 2.7.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/amarao/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15+ (default, Nov 28 2018, 16:27:22) [GCC 8.2.0]
CONFIGURATION
ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/etc/ansible/ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=10s
ANSIBLE_SSH_CONTROL_PATH(/etc/ansible/ansible.cfg) = /tmp/%%h-%%r
DEFAULT_SUDO_FLAGS(/etc/ansible/ansible.cfg) = -H -S
DEFAULT_TIMEOUT(/etc/ansible/ansible.cfg) = 15
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT

local: Ubuntu 19.04
remote: Ubuntu 18.04, grafana 5.4.2

STEPS TO REPRODUCE
- hosts: localhost
  tasks:
   - name: Configure datasource
     grafana_datasource:
       name: influx
       access: proxy
       basic_auth_user: admin
       basic_auth_password: admin
       ds_type: influxdb
       database: '{{ torture_database }}'
       grafana_url: http://127.0.0.1:3000
       grafana_user: admin
       grafana_password: admin
       is_default: true
       tls_skip_verify: true
       url: http://127.0.0.1:8086
EXPECTED RESULTS

changed only on first run.

ACTUAL RESULTS
ansible-playbook test.yaml
changed=1

ansible-playbook test.yaml
changed=1

grafana_annotations fails when used from collection.

SUMMARY

The callback is not working from the collection.

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible 2.9.2
  config file = /Users/remirey/dev/ansible_collections/community/grafana/tmp/ansible.cfg
  configured module search path = [u'/Users/remirey/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/remirey/.venv/grafana/lib/python2.7/site-packages/ansible
  executable location = /Users/remirey/.venv/grafana/bin/ansible
  python version = 2.7.13 (default, Apr  4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
STEPS TO REPRODUCE
# ansible.cfg
[defaults]
callback_whitelist = community.grafana.grafana_annotations

[callback_grafana_annotations]
grafana_url = http://127.0.0.1:3000/api/annotations
grafana_user = admin
grafana_password = admin
# test.yml
- hosts: localhost
  tasks:
      - debug:
          msg: "nothing to do"
EXPECTED RESULTS
ACTUAL RESULTS
[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

 [ERROR]: Could not submit message to Grafana: 'CallbackModule' object has no attribute 'grafana_url'


PLAY [localhost] ********************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] ************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "nothing to do"
}

PLAY RECAP **************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[WARNING]: Failure using method (v2_playbook_on_stats) in callback plugin (<ansible_collections.community.grafana.plugins.callback.grafana_annotations.CallbackModule object at
0x111685cd0>): 'CallbackModule' object has no attribute 'dashboard_id'

Support exporting a dashboard without its metadata (just like Grafana)

SUMMARY

Support exporting a dashboard without its metadata (just like Grafana). Metadata are only relevant for the current Grafana environment.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

community.grafana.grafana_dashboard

ADDITIONAL INFORMATION

The export state for the community.grafana.grafana_dashboard module currently results in a dashboard file consisting of a dashboard definition and some dashboard metadata specific to the current Grafana environment:

{
  "dashboard": {
    <dashboard definition>
  },
  "meta": {
    <dashboard metadata>
  }
}

This differs from Grafana's export functionality where the exported content simply consists of the dashboard definition:

{
  <dashboard definition>
}

This output is desired when the dashboard is meant to be imported into other Grafana environments.

How should this be supported? I have two ideas:

  1. Add an extra state save which corresponds to the current behavior. Change export to actually behave like Grafana's export functionality.
    This is IMHO a more intuitive naming scheme. It breaks compatibility though but perhaps that's acceptable since this collection is still version 0.x.x.

  2. Add a boolean flag export_with_metadata (or similar) which determines whether the dashboard is exported with or without metadata. This won't break compatibility if its default value is true.

Thoughts?

Error "plugin does not exist" on state: absent

SUMMARY

If a plugin is removed with state: absent a second run will throw an error.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_plugin

ANSIBLE VERSION
ansible 2.10.0rc3
  python version = 3.6.9 (default, Apr 18 2020, 01:56:04) [GCC 8.4.0]
CONFIGURATION
- name: install plugins
  with_list: "{{ plugins.results }}"
  notify: restart grafana-server
  community.grafana.grafana_plugin:
    name: "{{ item.item.key }}"
    grafana_plugin_url: "{{ item.files[-1].path }}"
    state: absent
    grafana_plugins_dir: "{{ grafana_plugins_dir }}"
    version: "{{ install_grafana_plugins[item.item.key].version }}"
OS / ENVIRONMENT

Grafana 7.1.1

STEPS TO REPRODUCE
  • 1st run: install plugin with present
  • 2nd run: uninstall plugin with absent
  • 3rd run: uninstall plugin with absent = error
EXPECTED RESULTS

Ansible Task result: no change

ACTUAL RESULTS

2nd run:

changed: [host] ... 'item': {'key': 'camptocamp-prometheus-alertmanager-datasource', 'value': {'url': 'https://grafana.com/api/plugins/camptocamp-prometheus-alertmanager-datasource/versions/0.0.7/download', 'fileglob': 'camptocamp-grafana-prometheus-alertmanager-datasource', 'version': '0.0.7', 'state': 'absent'}}, 'ansible_loop_var': 'item'})

3rd run:

failed: [host] ... "msg": "'/sbin/grafana-cli --pluginUrl camptocamp-grafana-prometheus-alertmanager-datasource-0.0.7-0-gc4d8c51.zip --pluginsDir /var/lib/grafana/plugins plugins uninstall camptocamp-prometheus-alertmanager-datasource' execution returned an error : [1] Removing plugin: camptocamp-prometheus-alertmanager-datasource\nError: ✗ plugin does not exist\n "}

Integration tests with grafana image

SUMMARY

Currently the integration tests are running against python:3.6 image and grafana service containers. While there are unit tests to check things like grafana_plugin.
It would be nice and way easier to also have integration tests which runs directly against the grafana containers. Imo it would not only be easier to write but also would be easier to check against things like #103 ?

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

Tests

Supported Ansible versions and testing

SUMMARY

In meta/runtime.yml, you claim to support Ansible 2.6+ (https://github.com/ansible-collections/community.grafana/blob/main/meta/runtime.yml; sorry I didn't notice this earlier). Neither Ansible 2.6 nor 2.7 do support collections, so this statement is clearly wrong. You need Ansible 2.8 or newer.

Also, you do not run tests with Ansible 2.8 and 2.9 (which support collections, and which you claim to support). The sanity tests for #130 fail when run with Ansible 2.9 (ansible/ansible#71795 (comment)), but since you do not run them with Ansible 2.9, you won't notice.

In fact, you only seem to be running tests against the devel branch of ansible-base, which is really not a good idea. You should test against all supported Ansible versions to be sure that the collection actually works with them.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

collection

Manually add secureJsonData

SUMMARY

Similarly to #102 a parameter to manually add secureJsonData would be needed to for example add Bearer tokens the secure way.
Note: already working on it, PR inbound.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

grafana_datasource

ADDITIONAL INFORMATION

The inconvenience here is, secureJsonData will get encrypted by grafana and returned as secureJsonFields - so there is no way to compare those dicts. As such each run ansible run the tasks will be changed=true.

Can't set datasource 'Access' to 'Server (default)'

SUMMARY

It is not possible to set a datasources 'Access' field to 'Server (default)' using ansible:

- name: create prometheus datasource
  community.grafana.grafana_datasource:
    name: local_prometheus
    access: direct
    ds_type: prometheus
    ds_url: 'http://127.0.0.1:9090'
    access: direct
    tls_skip_verify: true
    url: "https://{{ grafana_url }}"
    grafana_user: "admin"
    grafana_password: "{{ grafana_admin_password }}"

Set the 'access' variable here to 'direct' or 'proxy', it makes no difference, in the GUI the datasources 'Access' field will always be set to 'Browser'.

Graphana-trouble

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible 2.9.6
CONFIGURATION
$ ansible-config dump --only-changed
ANSIBLE_PIPELINING(/location/ansible.cfg) = True
RETRY_FILES_ENABLED(/location/ansible.cfg) = False
OS / ENVIRONMENT

Debian 10 for both the controller and the target.

STEPS TO REPRODUCE
Just use the above code.
EXPECTED RESULTS

I expected there to be some way to set this value to 'Server (default)' using ansible.

ACTUAL RESULTS

grafana_datasource doesn't set password correctly

SUMMARY

The grafana_datasource module does not configure the datasource password correctly. When used, the 'password' parameter is not used in the specified datasource. This might be due to the password being specified outside of the 'secureJsonData' parameter in the Grafana API request. See Grafana API docs on Creating a Datasource.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_datasource

ANSIBLE VERSION
ansible 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/derek/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/derek/.local/lib/python3.6/site-packages/ansible
  executable location = /home/derek/.local/bin/ansible
  python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
CONFIGURATION
(no output)
OS / ENVIRONMENT

Ubuntu 18.04 LTS

STEPS TO REPRODUCE

Use grafana_datasource to create a MySQL datasource with MySQL username and password specified using the user and password parameters.

  - name: provisioning datasources
    grafana_datasource:
      name: "{{ item.name }}"
      database: "{{ item.database}}"
      url: dsurl:port
      grafana_url: "{{ hostvars[inventory_hostname].grafurl }}"
      validate_certs: no
      grafana_api_key: "{{ hostvars[inventory_hostname].grafapikey }}"
      ds_type: mysql
      # any of the following reproduces the issue:
      user: testuser
      password: test123
      # 
      basic_auth_user: testuser
      basic_auth_password: test123
      # 
      basic_auth_user: testuser
      password: test123
      # 
EXPECTED RESULTS

The password is set and the datasource can be tested from the Grafana UI. The password field appears as 'configured' in a grayed out box. This matches behavior when the password is set through the UI.

ACTUAL RESULTS

The username is set however the password field remains blank in the UI and the datasource cannot be tested or used. The password must be set manually through the UI.

ansible@host:~/$ ansible host1.net -m grafana_datasource -a "name=authtest url=https://authtest:3306 access=proxy state=present grafana_url=https://host1.net validate_certs=no grafana_api_key=loTsOfLettErS ds_type=mysql database=testdb basic_auth_password=test123 basic_auth_user=testuser" -K -vvv
ansible 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ansible/.local/lib/python3.6/site-packages/ansible
  executable location = /home/ansible/.local/bin/ansible
  python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
Using /etc/ansible/ansible.cfg as config file
BECOME password:
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
META: ran handlers
<host1.net> ESTABLISH SSH CONNECTION FOR USER: None
<host1.net> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/9ec4a2bc8e host1.net '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<host1.net> (0, b'/home/ansible\n', b'')
<host1.net> ESTABLISH SSH CONNECTION FOR USER: None
<host1.net> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/9ec4a2bc8e host1.net '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/ansible/.ansible/tmp `"&& mkdir /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576 && echo ansible-tmp-1596772708.4799106-4131-56466493012576="` echo /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576 `" ) && sleep 0'"'"''
<host1.net> (0, b'ansible-tmp-1596772708.4799106-4131-56466493012576=/home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576\n', b'')
Using module file /home/ansible/.local/lib/python3.6/site-packages/ansible/modules/monitoring/grafana_datasource.py
<host1.net> PUT /home/ansible/.ansible/tmp/ansible-local-4126tv0mzdhb/tmp50x_scxa TO /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576/AnsiballZ_grafana_datasource.py
<host1.net> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/9ec4a2bc8e '[host1.net]'
<host1.net> (0, b'sftp> put /home/ansible/.ansible/tmp/ansible-local-4126tv0mzdhb/tmp50x_scxa /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576/AnsiballZ_grafana_datasource.py\n', b'')
<host1.net> ESTABLISH SSH CONNECTION FOR USER: None
<host1.net> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/9ec4a2bc8e host1.net '/bin/sh -c '"'"'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576/ /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576/AnsiballZ_grafana_datasource.py && sleep 0'"'"''
<host1.net> (0, b'', b'')
<host1.net> ESTABLISH SSH CONNECTION FOR USER: None
<host1.net> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/9ec4a2bc8e -tt host1.net '/bin/sh -c '"'"'sudo -H -S  -p "[sudo via ansible, key=ikkampdiahqechocotwsyoktdaldlfcz] password:" -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-ikkampdiahqechocotwsyoktdaldlfcz ; /usr/bin/python3 /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576/AnsiballZ_grafana_datasource.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<host1.net> (0, b'\r\n\r\n{"failed": false, "msg": "Datasource authtest created : Datasource added", "changed": true, "name": "authtest", "id": 45, "invocation": {"module_args": {"user": "testuser", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "name": "authtest", "url": "https://authtest:3306", "access": "proxy", "state": "present", "grafana_url": "https://host1.net", "validate_certs": false, "grafana_api_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "ds_type": "mysql", "database": "testdb", "basic_auth_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "basic_auth_user": "testuser", "use_proxy": true, "url_username": "admin", "url_password": "admin", "with_credentials": false, "tls_skip_verify": false, "is_default": false, "org_id": 1, "es_version": 5, "max_concurrent_shard_requests": 256, "time_field": "@timestamp", "interval": "", "tsdb_version": 1, "tsdb_resolution": "second", "sslmode": "disable", "trends": false, "aws_auth_type": "keys", "aws_default_region": "us-east-1", "aws_access_key": "", "aws_secret_key": "", "aws_credentials_profile": "", "aws_assume_role_arn": "", "client_cert": null, "client_key": null, "tls_client_cert": null, "tls_client_key": null, "tls_ca_cert": null, "time_interval": null, "aws_custom_metrics_namespaces": null}}}\r\n', b'Shared connection to host1.net closed.\r\n')
<host1.net> ESTABLISH SSH CONNECTION FOR USER: None
<host1.net> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/9ec4a2bc8e host1.net '/bin/sh -c '"'"'rm -f -r /home/ansible/.ansible/tmp/ansible-tmp-1596772708.4799106-4131-56466493012576/ > /dev/null 2>&1 && sleep 0'"'"''
<host1.net> (0, b'', b'')
host1.net | CHANGED => {
    "changed": true,
    "id": 45,
    "invocation": {
        "module_args": {
            "access": "proxy",
            "aws_access_key": "",
            "aws_assume_role_arn": "",
            "aws_auth_type": "keys",
            "aws_credentials_profile": "",
            "aws_custom_metrics_namespaces": null,
            "aws_default_region": "us-east-1",
            "aws_secret_key": "",
            "basic_auth_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "basic_auth_user": "testuser",
            "client_cert": null,
            "client_key": null,
            "database": "testdb",
            "ds_type": "mysql",
            "es_version": 5,
            "grafana_api_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "grafana_url": "https://host1.net",
            "interval": "",
            "is_default": false,
            "max_concurrent_shard_requests": 256,
            "name": "authtest",
            "org_id": 1,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "sslmode": "disable",
            "state": "present",
            "time_field": "@timestamp",
            "time_interval": null,
            "tls_ca_cert": null,
            "tls_client_cert": null,
            "tls_client_key": null,
            "tls_skip_verify": false,
            "trends": false,
            "tsdb_resolution": "second",
            "tsdb_version": 1,
            "url": "https://authtest:3306",
            "url_password": "admin",
            "url_username": "admin",
            "use_proxy": true,
            "user": "testuser",
            "validate_certs": false,
            "with_credentials": false
        }
    },
    "msg": "Datasource authtest created : Datasource added",
    "name": "authtest"
}
META: ran handlers
META: ran handlers

alerting notification channel support

SUMMARY

As a user I want to be able to define alerts which now miss notification channel setting via ansible.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

Probably missing such module. Settings module?

ADDITIONAL INFORMATION

Now I manage to create dashboards, which also has alerts. But all alerts are missing notification channel (email, chat, etc...) definition, so they won't get sent. I copied a dashboard with alert from manually created grafana. When I push that dashboard to new instance, it complains about not having alert notification channel. And that is missing from the new grafana.

Inclusion of community.grafana in Ansible 2.10

This collection will be included in Ansible 2.10 because it contains modules and/or plugins that were included in Ansible 2.9. Please review:

DEADLINE: 2020-08-18

The latest version of the collection available on August 18 will be included in Ansible 2.10.0, except possibly newer versions which differ only in the patch level. (For details, see the roadmap). Please release version 1.0.0 of your collection by this date! If 1.0.0 does not exist, the same 0.x.y version will be used in all of Ansible 2.10 without updates, and your 1.x.y release will not be included until Ansible 2.11 (unless you request an exception at a community working group meeting and go through a demanding manual process to vouch for backwards compatibility . . . you want to avoid this!).

Follow semantic versioning rules

Your collection versioning must follow all semver rules. This means:

  • Patch level releases can only contain bugfixes;
  • Minor releases can contain new features, new modules and plugins, and bugfixes, but must not break backwards compatibility;
  • Major releases can break backwards compatibility.

Changelogs and Porting Guide

Your collection should provide data for the Ansible 2.10 changelog and porting guide. The changelog and porting guide are automatically generated from ansible-base, and from the changelogs of the included collections. All changes from the breaking_changes, major_changes, removed_features and deprecated_features sections will appear in both the changelog and the porting guide. You have two options for providing changelog fragments to include:

  1. If possible, use the antsibull-changelog tool, which uses the same changelog fragment as the ansible/ansible repository (see the documentation).
  2. If you cannot use antsibull-changelog, you can provide the changelog in a machine-readable format as changelogs/changelog.yaml inside your collection (see the documentation of changelogs/changelog.yaml format).

If you cannot contribute to the integrated Ansible changelog using one of these methods, please provide a link to your collection's changelog by creating an issue in https://github.com/ansible-community/ansible-build-data/. If you do not provide changelogs/changelog.yml or a link, users will not be able to find out what changed in your collection from the Ansible changelog and porting guide.

Make sure your collection passes the sanity tests

Run ansible-test sanity --docker -v in the collection with the latest ansible-base or stable-2.10 ansible/ansible checkout.

Keep informed

Be sure you're subscribed to:

Questions and Feedback

If you have questions or want to provide feedback, please see the Feedback section in the collection requirements.

(Internal link to keep track of issues: ansible-collections/overview#102)

Create Grafana 'add annotation' module

SUMMARY

Add a single annotation to Grafana via Ansible, with dynamic variables (e.g. endpoint, dashboard_id's).

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

community.grafana.add_grafana_annotation

ADDITIONAL INFORMATION

I wanted to utilise Grafana annotations for my Ansible deployments, but the callback plugin seemed too limited for my use-case (different Grafana endpoints - various projects/environments and single Ansible repo, different dashboards to be updated by each role etc, which I believe is a common setup for many people).

An 'add annotation' module is more useful for that kind of operation, because it can utilise group_vars or defaults to achieve the desired result.

I have created a sample module at my GitHub, let me know if it needs anything else to be included in community.grafana.

- name: Create a Grafana annotation
  add_grafana_annotation:
    grafana_api_url: "https://grafana.myproject.com"
    grafana_api_key: "..."
    dashboard_id: 468
    panel_id: 20
    text: "Annotation description"
    tags:
      - tag1
      - tag2

JSON Decode Error when grafana_url ends with trailing slash

SUMMARY

When crafting a URL for Grafana's API, the grafana_datasource module (and maybe others, I didn't check them) appends two strings together, the passed in grafana_url and the appropriate endpoint. This results in a URL like "...com//api/..." Grafana is picky about matching routes, so returns an error page in HTML, not JSON as the module expects. It attempts to parse the page as JSON which results in a JSONDecodeError.

ISSUE TYPE
  • Bug Report
  • Feature Request

A bit of both, I think.

COMPONENT NAME
ANSIBLE VERSION
ansible 2.10.2
  config file = /home/user/code/homelab/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.6 (default, Sep 30 2020, 04:00:38) [GCC 10.2.0]
CONFIGURATION
DEPRECATION_WARNINGS(/home/user/code/homelab/ansible.cfg) = False
DIFF_ALWAYS(/home/user/code/homelab/ansible.cfg) = True
LOCALHOST_WARNING(/home/user/code/homelab/ansible.cfg) = False
OS / ENVIRONMENT

Arch Linux, targeting itself. Everything is installed from the distribution packages.

STEPS TO REPRODUCE

Simply running this playbook should trigger the error:

---
- name: create a datasource in grafana to read metrics
  community.grafana.grafana_datasource:
    name: "{{ item }}"
    grafana_url: "https://grafana.example.com/" # NB: the trailing slash
    grafana_api_key: "{{ grafana_admin_api_key }}"
    org_id: "1"
    ds_type: "influxdb"
    ds_url: "http://influx:8086"
    database: "telegraf"
    time_interval: ">10s"
    user: grafana
    password: "{{ influxdb_users_grafana }}"
EXPECTED RESULTS

Not a python exception, but either it gracefully handling it or returning a human friendly error message rather than a screen full of red error text. 😄

ACTUAL RESULTS
"module_stderr": "Traceback (most recent call last):\n  File \"/home/user/.ansible/tmp/ansible-tmp-1603857202.7836478-2983891-108174010981857/AnsiballZ_grafana_datasource.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/user/.ansible/tmp/ansible-tmp-1603857202.7836478-2983891-108174010981857/AnsiballZ_grafana_datasource.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/user/.ansible/tmp/ansible-tmp-1603857202.7836478-2983891-108174010981857/AnsiballZ_grafana_datasource.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_datasource', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.grafana.grafana_datasource_payload_oszg32vj/ansible_community.grafana.grafana_datasource_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_datasource.py\", line 752, in <module>\n  File \"/tmp/ansible_community.grafana.grafana_datasource_payload_oszg32vj/ansible_community.grafana.grafana_datasource_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_datasource.py\", line 726, in main\n  File \"/tmp/ansible_community.grafana.grafana_datasource_payload_oszg32vj/ansible_community.grafana.grafana_datasource_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_datasource.py\", line 628, in datasource_by_name\n  File \"/tmp/ansible_community.grafana.grafana_datasource_payload_oszg32vj/ansible_community.grafana.grafana_datasource_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_datasource.py\", line 617, in _send_request\n  File \"/tmp/ansible_community.grafana.grafana_datasource_payload_oszg32vj/ansible_community.grafana.grafana_datasource_payload.zip/ansible/module_utils/basic.py\", line 2136, in from_json\n  File \"/usr/lib/python3.8/json/__init__.py\", line 357, in loads\n    return _default_decoder.decode(s)\n  File \"/usr/lib/python3.8/json/decoder.py\", line 337, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n  File \"/usr/lib/python3.8/json/decoder.py\", line 355, in raw_decode\n    raise JSONDecodeError(\"Expecting value\", s, err.value) from None\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n

Can't create folder

SUMMARY

I try to create a folder and upload a dashboard

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_folder

ANSIBLE VERSION
❯ ansible --version
ansible 2.10.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/nicolas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.1 (default, Dec 13 2020, 11:55:53) [GCC 10.2.0]
CONFIGURATION

OS / ENVIRONMENT

Linux
Grafana 7.0

STEPS TO REPRODUCE
grafana_url: https://grafana.xxxxxxx.com
grafana_api_key: xxxxxxxxxxxx
grafana_dashboard_path: files/dashboards/
- name: Create a folder
  community.grafana.grafana_folder:
    url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    title: "commons"
    state: present

- name: Import Grafana dashboard Sk5/Commons
  community.grafana.grafana_dashboard:
    grafana_url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    commit_message: Updated by ansible
    overwrite: yes
    folder: commons
    path: "{{ grafana_dashboard_path }}/sk5-mixin/k8sclusteroverview.json"
EXPECTED RESULTS
  • A folder "commons" created
  • A dashboard uploaded
ACTUAL RESULTS

An error on folder creation :

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ***************************************************************************************************************************************************************************************************

TASK [minotor : Create a folder] ***********************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: invalid literal for int() with base 10: '0-beta3'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/nicolas/.ansible/tmp/ansible-tmp-1611602773.6373312-1482350-251097151758827/AnsiballZ_grafana_folder.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/nicolas/.ansible/tmp/ansible-tmp-1611602773.6373312-1482350-251097151758827/AnsiballZ_grafana_folder.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/nicolas/.ansible/tmp/ansible-tmp-1611602773.6373312-1482350-251097151758827/AnsiballZ_grafana_folder.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_folder', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 274, in <module>\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 254, in main\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 178, in __init__\n  File \"/tmp/ansible_community.grafana.grafana_folder_payload_2gl7pvlh/ansible_community.grafana.grafana_folder_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_folder.py\", line 209, in get_version\nValueError: invalid literal for int() with base 10: '0-beta3'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP *********************************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Upload dashboard without specify folder works fine :

- name: Import Grafana dashboard Sk5/Commons
  community.grafana.grafana_dashboard:
    grafana_url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    commit_message: Updated by ansible
    overwrite: yes
    # folder: sk5-commons
    path: "{{ grafana_dashboard_path }}/sk5-mixin/k8sclusteroverview.json"
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ***************************************************************************************************************************************************************************************************

TASK [minotor : Import Grafana dashboard Sk5/Commons] **************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

An dashboard is on Grafana.

Trying to upload dashboard to a non-existent folder, I've got no error but in debug i see an incorrect response:

- name: Import Grafana dashboard Sk5/Commons
  community.grafana.grafana_dashboard:
    grafana_url: "{{ grafana_url }}"
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    commit_message: Updated by ansible
    overwrite: yes
    folder: commons
    path: "{{ grafana_dashboard_path }}/sk5-mixin/k8sclusteroverview.json"
TASK [minotor : Import Grafana dashboard Sk5/Commons] **************************************************************************************************************************************************************
task path: /home/nicolas/Work/skale-5/minotor-mixins/minotor/ansible/roles/minotor/tasks/grafana.yml:16
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: nicolas
<127.0.0.1> EXEC /bin/sh -c 'echo ~nicolas && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/nicolas/.ansible/tmp `"&& mkdir "` echo /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939 `" && echo ansible-tmp-1611644323.457462-1501296-28685885933939="` echo /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939 `" ) && sleep 0'
Using module file /home/nicolas/Work/skale-5/minotor-mixins/venv/lib/python3.9/site-packages/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py
<127.0.0.1> PUT /home/nicolas/.ansible/tmp/ansible-local-150129282072vpi/tmpuk2rhce3 TO /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/AnsiballZ_grafana_dashboard.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/ /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/AnsiballZ_grafana_dashboard.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -n  -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-vrznksyuvpcacajbzlribdphxekycfzt ; /home/nicolas/Work/skale-5/minotor-mixins/venv/bin/python3 /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/AnsiballZ_grafana_dashboard.py'"'"' && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/nicolas/.ansible/tmp/ansible-tmp-1611644323.457462-1501296-28685885933939/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "client_cert": null,
            "client_key": null,
            "commit_message": "Updated by ansible",
            "dashboard_id": null,
            "dashboard_revision": "1",
            "folder": "commons",
            "grafana_api_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "grafana_url": "https://grafana.xxxxxxxxxxxx.com",
            "org_id": 1,
            "overwrite": true,
            "path": "files/dashboards//sk5-mixin/k8sclusteroverview.json",
            "slug": null,
            "state": "present",
            "uid": null,
            "url": "https://grafana.xxxxxxxxx.com",
            "url_password": "admin",
            "url_username": "admin",
            "use_proxy": true,
            "validate_certs": true
        }
    },
    "msg": "Dashboard folder 'commons' does not exist.",
    "uid": "72b917dce60538f3282c1c4ed7c277d8"
}
Read vars_file './env_vars/{{ env }}/minotor.yml'
META: ran handlers
Read vars_file './env_vars/{{ env }}/minotor.yml'
META: ran handlers

PLAY RECAP *********************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

grafana_datasource not idempotent

SUMMARY

Running the grafana_datasource module always (with same args) results in changed=True.
The check in line 597
if ds.get('readOnly'): del ds['readOnly']
yields False due to the value 'False' of the key 'readOnly', so the key won't be deleted. But the excepted behaviour would be to delete the key due to its existence. So the later check in line 609
if ds == payload:
yields False and therefore
result['changed'] = True
instead of False.
The suggested fix would be
if ds.has_key('readOnly'): del ds['readOnly']

ISSUE TYPE
  • Bug Report

grafana_dashboard: can't override db after changed in GUI

SUMMARY

Can't override existing DBs if changed with this "new" module (from collection grafana)
DB changed after export in GUI

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_dashboard

ANSIBLE VERSION
ansible 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Nov  7 2019, 10:07:09) [GCC 7.4.0]

collection:
community.grafana 0.2.1
CONFIGURATION
DEFAULT_KEEP_REMOTE_FILES(env: ANSIBLE_KEEP_REMOTE_FILES) = True
ENABLE_TASK_DEBUGGER(env: ANSIBLE_ENABLE_TASK_DEBUGGER) = True
OS / ENVIRONMENT

Ubuntu 18.04.3 LTS

STEPS TO REPRODUCE
  1. Export an existing dashboard from your grafana via the module state=export
  2. Change the dashboard via the GUI. E.g. duplicate a graph.
  3. Import the json (from step 1). Set override=yes and state=present
---
- hosts: localhost
  collections:
    - community.grafana
  tasks:
  - name: Export dashboard
    grafana_dashboard:
      grafana_url: https://grafana.example.com
      grafana_api_key: "example"
      state: export
      uid: "Q9K5pvrWz"
      path: "/home/user/grafana/Q9K5pvrWz.json"


---
- hosts: localhost
  collections:
    - community.grafana
  tasks:
  - name: Import dashboard
    grafana_dashboard:
      grafana_url: https://grafana.example.com
      grafana_api_key: "example"
      state: present
      commit_message: Updated by ansible
      overwrite: yes
      path: "/home/user/grafana/Q9K5pvrWz.json"
EXPECTED RESULTS

The grafana dashboard should be overridden.

This happens when you use the grafana_dashboard from the ansible 2.9 version.

ACTUAL RESULTS
ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "client_cert": null,
            "client_key": null,
            "commit_message": "Updated by ansible",
            "dashboard_id": null,
            "dashboard_revision": "1",
            "folder": "General",
            "grafana_api_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "grafana_url": "https://grafana.example.com",
            "org_id": 1,
            "overwrite": true,
            "path": "/home/user/grafana/Q9K5pvrWz.json",
            "slug": null,
            "state": "present",
            "uid": null,
            "url": "https://grafana.example.com",
            "url_password": "admin",
            "url_username": "admin",
            "use_proxy": true,
            "validate_certs": true
        }
    },
    "msg": "Dashboard Ansible unchanged.",
    "uid": "Q9K5pvrWz"
}

I found out that I will not reach the line 288 in the grafana_dashboard_changed def: https://github.com/ansible-collections/grafana/blob/243ee4a8e14a56d21dddf73c8ae52747e0b9e21c/plugins/modules/grafana_dashboard.py#L288

[postgres] database password set as secureJsonData AND password

SUMMARY

Currently the module parameter password sends the data to API set in password and also in secureJsonData.

{
  "password": "iamgroot",
  "secureJsonData": {
    "password": "iamgroot",
  }
}

But with #107 the secureJsonData portion will not be updated ever. It still works because it is also provided unencrypted.

Will get fixed with #108

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_datasource

grafana_folder: unable to use spaces or other utf-8 chars in name/title

SUMMARY

grafana_folder: unable to use spaces or other utf-8 chars in name/title

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_folder

ANSIBLE VERSION
ansible 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Nov  7 2019, 10:07:09) [GCC 7.4.0]

collection:
community.grafana 0.2.1
CONFIGURATION
DEFAULT_KEEP_REMOTE_FILES(env: ANSIBLE_KEEP_REMOTE_FILES) = True
OS / ENVIRONMENT

Ubuntu 18.04.3 LTS

STEPS TO REPRODUCE

Try to use space or äöü in title for the folder

---
- hosts: localhost
  collections:
    - community.grafana
  tasks:
  - name: Export dashboard
    grafana_folder:
      grafana_url: https://grafana.example.com
      grafana_api_key: "..."
      state: present
      title: "{{ item }}"
    with_items:
      - Test DB 1
      - Test DB Ä
      - TEST DB ʦ
      - TEST DB ɮ
      - TEST DB Ŕ
      - TEST DB ‰
EXPECTED RESULTS

Folder should be created.

ACTUAL RESULTS

Error, because not URL quote for the get_folder API query.

msg": "Grafana Folders API answered with HTTP -1"

grafana_plugin with offline .zip package fails

SUMMARY

If using an offline .zip package for plugin installation the command fails while the plugin is actually installed correctly.

See ansible issue ansible/ansible#67042

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_plugin

ANSIBLE VERSION
ansible 2.9.4
  config file = /mnt/d/Code/gitlab/poi-central-grafana/ansbile/ansible.cfg
  configured module search path = ['/home/fism/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /mnt/d/Code/gitlab/grafana/venv/lib/python3.6/site-packages/ansible
  executable location = /mnt/d/Code/gitlab/grafana/venv/bin/ansible
  python version = 3.6.9 (default, Nov  7 2019, 10:44:02) [GCC 8.3.0]
OS / ENVIRONMENT

Grafana 6.6.0 on RHEL7

STEPS TO REPRODUCE
tasks:
    - name: Install/update zabbix plugin
      become: yes
      grafana_plugin:
        name: alexanderzobnin-grafana-zabbix
        grafana_plugin_url: "/tmp/alexanderzobnin-grafana-zabbix-v3.10.5-1-g2219691.zip"
        state: present

Running this task results in the error seen below while grafana-cli ls reports:

installed plugins:
alexanderzobnin-zabbix-app @ 3.10.5

Restart grafana after installing plugins . <service grafana-server restart>

Also tried to manually execute the command the module is triggering:
/sbin/grafana-cli --pluginUrl /tmp/alexanderzobnin-grafana-zabbix-v3.10.5-1-g2219691.zip plugins install alexanderzobnin-grafana-zabbix

Which results in:

installing alexanderzobnin-grafana-zabbix @
from: /tmp/alexanderzobnin-grafana-zabbix-v3.10.5-1-g2219691.zip
into: /var/lib/grafana/plugins

✔ Installed alexanderzobnin-grafana-zabbix successfully

Restart grafana after installing plugins . <service grafana-server restart>
EXPECTED RESULTS

as the plugin is correctly installing the plugin it should report a success.

ACTUAL RESULTS

Module error:

The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_grafana_plugin_payload_39EwDA/ansible_grafana_plugin_payload.zip/ansible/modules/monitoring/grafana_plugin.py", line 236, in main
  File "/tmp/ansible_grafana_plugin_payload_39EwDA/ansible_grafana_plugin_payload.zip/ansible/modules/monitoring/grafana_plugin.py", line 210, in grafana_plugin

fatal: [****]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "grafana_plugin_url": "/tmp/alexanderzobnin-grafana-zabbix-v3.10.5-1-g2219691.zip",
            "grafana_plugins_dir": null,
            "grafana_repo": null,
            "name": "alexanderzobnin-grafana-zabbix",
            "state": "present",
            "version": null
        }
    },
    "msg": "<type 'exceptions.ValueError'> : need more than 1 value to unpack "
}

Unable to create Elasticsearch datasource with es_version: 70

SUMMARY

Error: FAILED! => {"changed": false, "msg": "value of es_version must be one of: 2, 5, 56, got: 70"}

Appears to be supported:

/plugins/modules/grafana_datasource.py
es_version:
    description:
    - Elasticsearch version (for C(ds_type = elasticsearch) only)
    - Version 56 is for elasticsearch 5.6+ where you can specify the C(max_concurrent_shard_requests)
      option.
    choices:
    - 2
    - 5
    - 56
    - 60
    - 70
    default: 5
    type: int
ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_datasource

ANSIBLE VERSION
ansible 2.9.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/Users/$home/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]
CONFIGURATION
NO CHANGES
verified COLLECTION_PATH
verified collection installed to path
OS / ENVIRONMENT

Tested on Mac OS 10.15.5 as well as Linux 20.04.1

STEPS TO REPRODUCE

Run playbook which calls for:

collections:
    - community.grafana

when it attempts to process the datasource.yml, the above error is produced

datasource.yml
- name: Create EC Certificates datasource
  grafana_datasource:
    name: "EC - certificates"
    grafana_url: "{{ grafana_url }}"
    grafana_user: "{{ grafana_admin }}"
    grafana_password: "{{ grafana_pass }}"
    org_id: "1"
    ds_type: "elasticsearch"
    ds_url: "{{ elastic_url }}"
    database: "{{ index_id }}"
    basic_auth_user: "{{ elastic_user }}"
    basic_auth_password: "{{ elastic_pass }}"
    time_field: "@timestamp"
    time_interval: "1m"
    es_version: 70
    max_concurrent_shard_requests: 5
EXPECTED RESULTS

Create the datasource with Elasticsearch version 7.0+

ACTUAL RESULTS
FAILED! => {"changed": false, "msg": "value of es_version must be one of: 2, 5, 56, got: 70"}

Plugin Datasources aren't possible

SUMMARY

Currently the possible datasources are hardcoded so ds from plugins like camptocamp-prometheus-alertmanager-datasource aren't possible.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

grafana_datasource

Dashboard creation fails on Grafana 4

SUMMARY

When creating a new dashboard on Grafana 4 the operation fails with:

UnboundLocalError: local variable 'folder_exists' referenced before assignment

The folder_exists variable only gets assigned when Grafana version is 5 or greater.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.grafana.grafana_dashboard

ANSIBLE VERSION
ansible 2.10.0
  config file = None
  configured module search path = ['/home/olli/.local/share/ansible/plugins/modules']
  ansible python module location = /nix/store/j7shbb56dxrfpc03kxr7g4chn9kpp95w-python3.8-ansible-2.10.0/lib/python3.8/site-packages/ansible
  executable location = /nix/store/j7shbb56dxrfpc03kxr7g4chn9kpp95w-python3.8-ansible-2.10.0/bin/ansible
  python version = 3.8.7 (default, Dec 21 2020, 17:18:55) [GCC 10.2.0]
CONFIGURATION
OS / ENVIRONMENT

NixOS unstable

STEPS TO REPRODUCE

This command sequence should demonstrate the problem.

mkdir -p api/frontend
echo '{"buildInfo":{"version":"4.0.0"}}' > api/frontend/settings
echo '{}' > test.json
python -m http.server &
ansible -m community.grafana.grafana_dashboard -a 'grafana_url=http://localhost:8000 slug=test path=test.json grafana_api_key=test' localhost
kill %1 # stop http.server
EXPECTED RESULTS

Dashboard creation succeeds. Or with the above command sequence fails due to something that is not a bug :)

ACTUAL RESULTS
127.0.0.1 - - [26/Jan/2021 15:08:22] "GET /api/frontend/settings HTTP/1.1" 200 -
127.0.0.1 - - [26/Jan/2021 15:08:22] "GET /api/frontend/settings HTTP/1.1" 200 -
127.0.0.1 - - [26/Jan/2021 15:08:22] code 404, message File not found
127.0.0.1 - - [26/Jan/2021 15:08:22] "GET /api/dashboards/db/test HTTP/1.1" 404 -
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'folder_exists' referenced before assignment
localhost | FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible-tmp-1611666501.8013935-32225-186495449997119/AnsiballZ_grafana_dashboard.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/tmp/ansible-tmp-1611666501.8013935-32225-186495449997119/AnsiballZ_grafana_dashboard.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/tmp/ansible-tmp-1611666501.8013935-32225-186495449997119/AnsiballZ_grafana_dashboard.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_dashboard', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/nix/store/2wwb85hrvvfzkhrlwcj3pqi60nlbi9cq-python3-3.8.7/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/nix/store/2wwb85hrvvfzkhrlwcj3pqi60nlbi9cq-python3-3.8.7/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/nix/store/2wwb85hrvvfzkhrlwcj3pqi60nlbi9cq-python3-3.8.7/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/run/user/1000/ansible_community.grafana.grafana_dashboard_payload_71m883ko/ansible_community.grafana.grafana_dashboard_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py\", line 563, in <module>\n  File \"/run/user/1000/ansible_community.grafana.grafana_dashboard_payload_71m883ko/ansible_community.grafana.grafana_dashboard_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py\", line 525, in main\n  File \"/run/user/1000/ansible_community.grafana.grafana_dashboard_payload_71m883ko/ansible_community.grafana.grafana_dashboard_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py\", line 388, in grafana_create_dashboard\nUnboundLocalError: local variable 'folder_exists' referenced before assignment\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Unwrapped module_stderr:

Traceback (most recent call last):
  File "/tmp/ansible-tmp-1611666501.8013935-32225-186495449997119/AnsiballZ_grafana_dashboard.py", line 102, in <module>
    _ansiballz_main()
  File "/tmp/ansible-tmp-1611666501.8013935-32225-186495449997119/AnsiballZ_grafana_dashboard.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/tmp/ansible-tmp-1611666501.8013935-32225-186495449997119/AnsiballZ_grafana_dashboard.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.grafana.plugins.modules.grafana_dashboard', init_globals=None, run_name='__main__', alter_sys=True)
  File "/nix/store/2wwb85hrvvfzkhrlwcj3pqi60nlbi9cq-python3-3.8.7/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/nix/store/2wwb85hrvvfzkhrlwcj3pqi60nlbi9cq-python3-3.8.7/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/nix/store/2wwb85hrvvfzkhrlwcj3pqi60nlbi9cq-python3-3.8.7/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/run/user/1000/ansible_community.grafana.grafana_dashboard_payload_71m883ko/ansible_community.grafana.grafana_dashboard_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py", line 563, in <module>
  File "/run/user/1000/ansible_community.grafana.grafana_dashboard_payload_71m883ko/ansible_community.grafana.grafana_dashboard_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py", line 525, in main
  File "/run/user/1000/ansible_community.grafana.grafana_dashboard_payload_71m883ko/ansible_community.grafana.grafana_dashboard_payload.zip/ansible_collections/community/grafana/plugins/modules/grafana_dashboard.py", line 388, in grafana_create_dashboard
UnboundLocalError: local variable 'folder_exists' referenced before assignment

is_admin does not work for user

SUMMARY

I used this module, and noticed is_admin: true -types of users end up being viewers only in grafana.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_user.py

ANSIBLE VERSION
ansible 2.9.16
  config file = /home/itengval/src/ansible-test/ansible.cfg
  configured module search path = ['/home/itengval/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Aug 18 2020, 08:33:21) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

CONFIGURATION
ANSIBLE_PIPELINING(/home/itengval/src/ansible-test/ansible.cfg) = True
DEFAULT_CALLBACK_WHITELIST(/home/itengval/src/ansible-test/ansible.cfg) = ['timer']
DEFAULT_ROLES_PATH(/home/itengval/src/ansible-test/ansible.cfg) = ['/home/itengval/src/ansible-test/roles']
HOST_KEY_CHECKING(/home/itengval/src/ansible-test/ansible.cfg) = False

OS / ENVIRONMENT

RHEL 8.3

STEPS TO REPRODUCE

All the users on the list become viewers, not admins.

---
grafana_admins:
  - login: test-admin
    name: 'Test Admin'
    email: '[email protected]'
    password: 'test'
grafana_users:
  - login: test-user
    name: 'Test User'
    email: '[email protected]'
    password: 'test'


---
- name: Ensure admins
  tags: push
  community.grafana.grafana_user:
    url: "{{ grafana_url }}"
    url_username: "{{ grafana_admin }}"
    url_password: "{{ grafana_admin_password }}"
    name: "{{ item.name }}"
    email: "{{ item.email }}"
    login: "{{ item.login }}"
    password: "{{ item.password }}"
    is_admin: true
    state: present
  no_log: true
  loop: "{{ grafana_admins }}"

- name: Ensure users
  tags: push
  community.grafana.grafana_user:
    grafana_url: "{{ grafana_url }}"
    url_username: "{{ grafana_admin }}"
    url_password: "{{ grafana_admin_password }}"
    name: "{{ item.name }}"
    email: "{{ item.email }}"
    login: "{{ item.login }}"
    password: "{{ item.password }}"
    is_admin: false
    state: present
  no_log: true
  loop: "{{ grafana_users }}"
EXPECTED RESULTS

is_admin to make user and admin

ACTUAL RESULTS

all become viewers.

Rename repo community.grafana

SUMMARY

Hi,
To be more consistent with the other repos https://github.com/ansible-collections/ I'd like to rename this GitHub Repo to be community.grafana

  • Old URLs for issues and PRs will still work
  • Old git URLs will work, though it will be good to update them locally
  • We will need to update the URLs in galaxy.yml & README

Are you happy with this?

ISSUE TYPE
  • Bug Report

Cannot create datasource with slash in name

ansible 2.9.12

Module tries to check existence of the datasource by it's name, and fails when name contains a slash. Seems that name is not escaped properly.

Working:

grafana_datasource:
  name: "FOO"

Not working:

grafana_datasource:
  name: "FOO / BAR"

Refactor grafana_datasource

SUMMARY

grafana_datasource is a big module handling a lot of combination for the different datasources.
I wonder if we could rework it to make it easier to maintain.
I was thinking about using ansible actions that would call other modules focused on specific datasources. A bit like package is wrapping yum and/or apt.

It would give something like this:

plugins/actions/grafana_datasource.py
plugins/modules/_grafana_datasource_influx.py
plugins/modules/_grafana_datasource_elastic.py
plugins/modules/_grafana_datasource_prometheus.py

@seuf what do you think about this ?

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

grafana_datasource.py

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.