New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify configuration of datasources #4
Conversation
example/group_vars/all
Outdated
port: 9200 | ||
host: monasca-elasticsearch | ||
# For elasticsearch DB name | ||
grafana_conf_project_id: "some-id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be just project_id?
tasks/main.yml
Outdated
"{{ grafana_conf_grafana_datasource_definitions[item.key] }}" | ||
register: grafana_conf_enabled_datasources | ||
with_dict: | ||
"{{ grafana_conf_grafana_datasources }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about building the grafana_conf_enabled_datasources list in one set_fact task?
- set_fact:
my_var: [] - set_fact:
my_var: "{{ my_var + [item] }}"
with_dict: my_dict
I lied. it's still two. You could initialise the list in defaults if you wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems cleaner - thanks. Ready for re-review.
This also fixes an issue where the playbook will fail if no dashboards were found, or specified.
1185513
to
20f54aa
Compare
tasks/main.yml
Outdated
grafana_conf_enabled_datasources: | ||
"{{ grafana_conf_enabled_datasources + [grafana_conf_grafana_datasource_definitions[item.key]] }}" | ||
with_dict: | ||
"{{ grafana_conf_grafana_datasources | default({}, True) }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Why not put grafana_conf_grafana_datasources in defaults and remove the default here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
defaults/main.yml
Outdated
@@ -23,7 +26,7 @@ grafana_conf_grafana_datasource_definitions: | |||
"user": "", | |||
"password": "", | |||
"type": "monasca-datasource", | |||
"url": "http://{{ grafana_conf_monasca_api.host }}:{{ grafana_conf_monasca_api.port }}/", | |||
"url": "http://{{ item.value.host }}:{{ item.value.port }}/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a small (optional) usability enhancement you could set a task variable, then reference that instead of item.host
.
vars:
datasource: "{{ item.value }}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion - fixed.
tasks/main.yml
Outdated
|
||
- name: Clone dashboards | ||
git: | ||
repo: "{{ grafana_conf_grafana_dashboard_repo.path }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example has this as .repo
, which matches the module arguments better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tasks/main.yml
Outdated
- name: Clone dashboards | ||
git: | ||
repo: "{{ grafana_conf_grafana_dashboard_repo.path }}" | ||
dest: "{{ grafana_conf_grafana_dashboard_repo.checkout_path }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also support an optional .version
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
with_items: "{{ grafana_conf_available_dashboards['files'] }}" | ||
with_items: | ||
- "{{ grafana_conf_available_dashboards_git['files'] | default([]) }}" | ||
- "{{ grafana_conf_available_dashboards_path['files'] | default([]) }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a nested list, does that still work, or should we be using with_items over a concatenated list, or using with_nested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it works although it would be clearer to explicitly concatenate them. Much to some peoples dislike it flattens the list of lists: ansible/ansible#5913
Ready for re-review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looks like I forgot to submit my comments.
tasks/main.yml
Outdated
@@ -98,13 +101,14 @@ | |||
owner: "{{ ansible_user_id }}" | |||
group: "{{ ansible_user_id }}" | |||
become: True | |||
when: grafana_conf_grafana_dashboard_repo | bool | |||
when: grafana_conf_grafana_dashboard_repo is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think | bool was better - the default means that it will always be defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the bool filter was causing this and the one below to be skipped. I should go back and investigate exactly how it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's not always obvious how to check things like this. One way that works fairly well is to set the variable to None in defaults:
my_var:
Then check with may_var is not none
. That would require changes in kayobe too though. There's also my_var != {}
and my_var | length > 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - it should be more robust now. I've checked it behaves with Kayobe defaults, with a repo set, and with some missing repo information.
tasks/main.yml
Outdated
dest: "{{ grafana_conf_grafana_dashboard_repo.checkout_path }}" | ||
when: grafana_conf_grafana_dashboard_repo | bool | ||
version: "{{ grafana_conf_grafana_dashboard_repo.version | default('HEAD') }}" | ||
when: grafana_conf_grafana_dashboard_repo is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
71ede9f
to
d78e6b4
Compare
tasks/main.yml
Outdated
grafana_conf_dashboard_repo_set: "{{ | ||
(grafana_conf_grafana_dashboard_repo.repo is not none) and | ||
(grafana_conf_grafana_dashboard_repo.checkout_path is not none) and | ||
(grafana_conf_grafana_dashboard_repo.relative_path is not none) }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this break with the role default, an empty dict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh :( Thanks!
d78e6b4
to
658907e
Compare
Ready for review. |
No description provided.