Skip to content
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

Merged
merged 10 commits into from Jan 29, 2018

Conversation

dougszumski
Copy link
Member

No description provided.

port: 9200
host: monasca-elasticsearch
# For elasticsearch DB name
grafana_conf_project_id: "some-id"
Copy link
Member

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 }}"
Copy link
Member

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.

Copy link
Member Author

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.
@dougszumski dougszumski force-pushed the feature/simplify_datasource_config branch from 1185513 to 20f54aa Compare January 22, 2018 16:16
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) }}"
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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 }}/",
Copy link
Member

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 }}"

Copy link
Member Author

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 }}"
Copy link
Member

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.

Copy link
Member Author

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 }}"
Copy link
Member

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?

Copy link
Member Author

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([]) }}"
Copy link
Member

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?

Copy link
Member Author

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

@dougszumski
Copy link
Member Author

Ready for re-review.

Copy link
Member

@markgoddard markgoddard left a 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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

@dougszumski dougszumski force-pushed the feature/simplify_datasource_config branch from 71ede9f to d78e6b4 Compare January 24, 2018 17:49
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) }}"
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh :( Thanks!

@dougszumski dougszumski force-pushed the feature/simplify_datasource_config branch from d78e6b4 to 658907e Compare January 24, 2018 21:35
@dougszumski
Copy link
Member Author

Ready for review.

@dougszumski dougszumski merged commit 66224ef into master Jan 29, 2018
@dougszumski dougszumski deleted the feature/simplify_datasource_config branch January 29, 2018 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants