grafana / grafana-ansible-collection

grafana.grafana Ansible collection provides modules and roles for managing various resources on Grafana Cloud and roles to manage and deploy Grafana Agent and Grafana
https://docs.ansible.com/ansible/latest/collections/grafana/grafana/index.html#plugins-in-grafana-grafana
GNU General Public License v3.0
131 stars 87 forks source link

Grafana role - check mode broken when grafana_dashboards is used #245

Open tivoscappini opened 3 months ago

tivoscappini commented 3 months ago

When grafana_dashboards is non-empty, applying the Grafana role in check mode fails with an error:

TASK [grafana.grafana.grafana : Create local grafana dashboard directory] ******                                                                                                                                                              
skipping: [test-deployment-monitoring-0] => {                                                                                                                                                                                                 
    "changed": false,                                                                                                                                                                                                                         
    "invocation": {                                                                                                                                                                                                                           
        "module_args": {                                                                                                                                                                                                                      
            "path": null,                                                                                                                                                                                                                     
            "prefix": "ansible.",                                                                                                                                                                                                             
            "state": "directory",                                                                                                                                                                                                             
            "suffix": ""                                                                                                                                                                                                                      
        }                                                                                                                                                                                                                                     
    },                                                                                                                                                                                                                                        
    "msg": "remote module (ansible.builtin.tempfile) does not support check mode"                                                                                                                                                             
}
TASK [grafana.grafana.grafana : Download grafana dashboard from grafana.net to local directory] ***                                                                                                                                           
fatal: [test-deployment-monitoring-0 -> localhost]: FAILED! => {                                                                                                                                                                              
    "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'path'\n\nThe error appears to be in '/opt/ansible/collections/ansible_collections/grafana/grafana/roles/grafana/
tasks/dashboards.yml': line 17, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  block:\n    - name: \"Download grafana dashboard from grafana.net to local direct
ory\"\n      ^ here\n"                                                                                                                                                                                                                        
}

The ansible.builtin.tempfile module used by the task "Create local grafana dashboard directory" does not support check mode and thus skips itself. The consequence is that its output __tmp_dashboards is not registered, so when the following task ("Download grafana dashboard from grafana.net to local directory") tries to reference this registered variable to configure its ansible.builtin.get_url module, Ansible cannot resolve the reference and the task fails with an error.

It looks like a similar problem was solved in #125 for provisioned dashboards, but the problem remains for grafana.net dashboards.

JMLX42 commented 1 week ago

Fix in #283