From c3b6c01c6d1d5dfe4381de58ec07cfbd167dc6e3 Mon Sep 17 00:00:00 2001 From: Sergey Malyuk Date: Fri, 12 Dec 2025 16:10:28 +0300 Subject: [PATCH] fix linter errors --- roles/grafana/README.md | 16 ++-- roles/grafana/defaults/main.yml | 10 +-- roles/grafana/meta/main.yml | 4 +- roles/grafana/molecule/default/converge.yml | 6 +- .../datasources/test_datasource_loki.yaml | 2 +- .../test_datasource_prometheus.yaml | 78 +++++++++---------- roles/grafana/molecule/default/verify.yml | 2 +- roles/grafana/tasks/dashboards.yml | 6 +- roles/grafana/tasks/datasources.yml | 4 +- roles/grafana/tasks/install.yml | 10 +-- roles/grafana/tasks/plugins.yml | 4 +- roles/grafana/templates/grafana-server.env.j2 | 6 +- 12 files changed, 74 insertions(+), 74 deletions(-) diff --git a/roles/grafana/README.md b/roles/grafana/README.md index 5181eb8..a700863 100644 --- a/roles/grafana/README.md +++ b/roles/grafana/README.md @@ -14,7 +14,7 @@ This role installs and configures Grafana from a binary distribution. It also: - Allows admin password changes Supports user creation - Grafana service requires an environment file at startup, where you can set custom paths for logs (`log_dir`), data (`data_dir`), and plugins (`plugins_dir`). This allows flexible control over Grafana's data storage. + Grafana service requires an environment file at startup, where you can set custom paths for logs (`grafana_log_dir`), data (`grafana_data_dir`), and plugins (`grafana_plugins_dir`). This allows flexible control over Grafana's data storage. Requirements ------------ @@ -31,11 +31,11 @@ grafana_version: 11.5.0 # version grafana_port: 3000 # port # Directory paths -dashboard_dir: "/tmp/grafana/dashboards" # where to copy dashboards from source -plugins_dir: "/var/lib/grafana/plugins" # where to store plugins on target -datasource_dir: "/etc/grafana/provisioning/datasources" # where to store data sources on target -log_dir: "/var/log/grafana" # where to write logs -data_dir: "/var/lib/grafana" # where to store Grafana DB +grafana_dashboard_dir: "/tmp/grafana/dashboards" # where to copy dashboards from source +grafana_plugins_dir: "/var/lib/grafana/plugins" # where to store plugins on target +grafana_datasource_dir: "/etc/grafana/provisioning/datasources" # where to store data sources on target +grafana_log_dir: "/var/log/grafana" # where to write logs +grafana_data_dir: "/var/lib/grafana" # where to store Grafana DB # Optional configurations grafana_users: [] # array of user names, passwords, and statuses @@ -91,8 +91,8 @@ Example Playbook public_dashboards: "{{ grafana_public_dashboards }}" dashboard_source_path: "molecule/default/dashboards" datasource_source_path: "molecule/default/datasources" - log_dir: "/opt/grafana/data" - data_dir: "/opt/grafana/lib" + grafana_log_dir: "/opt/grafana/data" + grafana_data_dir: "/opt/grafana/lib" ``` diff --git a/roles/grafana/defaults/main.yml b/roles/grafana/defaults/main.yml index aa32a25..535854f 100644 --- a/roles/grafana/defaults/main.yml +++ b/roles/grafana/defaults/main.yml @@ -3,8 +3,8 @@ grafana_user: "grafana" grafana_group: "grafana" grafana_version: 11.5.0 grafana_port: 3000 -dashboard_dir: "/tmp/grafana/dashboards" -plugins_dir: "/var/lib/grafana/plugins" -datasource_dir: "/etc/grafana/provisioning/datasources" -log_dir: "/var/log/grafana" -data_dir: "/var/lib/grafana" +grafana_dashboard_dir: "/tmp/grafana/dashboards" +grafana_plugins_dir: "/var/lib/grafana/plugins" +grafana_datasource_dir: "/etc/grafana/provisioning/datasources" +grafana_log_dir: "/var/log/grafana" +grafana_data_dir: "/var/lib/grafana" diff --git a/roles/grafana/meta/main.yml b/roles/grafana/meta/main.yml index 7d3782f..cec0dd3 100644 --- a/roles/grafana/meta/main.yml +++ b/roles/grafana/meta/main.yml @@ -10,8 +10,8 @@ galaxy_info: platforms: - name: "Ubuntu" - versions: [ "focal", "jammy", "noble" ] + versions: ["focal", "jammy", "noble"] - galaxy_tags: [ ] + galaxy_tags: [] dependencies: [] diff --git a/roles/grafana/molecule/default/converge.yml b/roles/grafana/molecule/default/converge.yml index 136f248..a73b0da 100644 --- a/roles/grafana/molecule/default/converge.yml +++ b/roles/grafana/molecule/default/converge.yml @@ -31,7 +31,7 @@ roles: # kics-scan ignore-block - - role: genlab.grafana + - role: genlab.common.grafana grafana_version: 11.5.0 admin_api_username: "{{ grafana.admin_api_username }}" admin_api_password: "{{ grafana.admin_api_password }}" @@ -40,5 +40,5 @@ public_dashboards: "{{ grafana_public_dashboards }}" dashboard_source_path: "molecule/default/dashboards" datasource_source_path: "molecule/default/datasources" - log_dir: "/opt/grafana/data" - data_dir: "/opt/grafana/lib" + grafana_log_dir: "/opt/grafana/data" + grafana_data_dir: "/opt/grafana/lib" diff --git a/roles/grafana/molecule/default/datasources/test_datasource_loki.yaml b/roles/grafana/molecule/default/datasources/test_datasource_loki.yaml index 335bacc..9c3ede0 100644 --- a/roles/grafana/molecule/default/datasources/test_datasource_loki.yaml +++ b/roles/grafana/molecule/default/datasources/test_datasource_loki.yaml @@ -13,4 +13,4 @@ datasources: secureJsonData: httpHeaderValue1: "Bearer your_token_here" version: 1 - editable: false \ No newline at end of file + editable: false diff --git a/roles/grafana/molecule/default/datasources/test_datasource_prometheus.yaml b/roles/grafana/molecule/default/datasources/test_datasource_prometheus.yaml index 5e334f1..56ec0c6 100644 --- a/roles/grafana/molecule/default/datasources/test_datasource_prometheus.yaml +++ b/roles/grafana/molecule/default/datasources/test_datasource_prometheus.yaml @@ -9,42 +9,42 @@ apiVersion: 1 # list of datasources to insert/update depending # whats available in the database datasources: - # name of the datasource. Required -- name: Prometheus - # datasource type. Required - type: prometheus - # access mode. direct or proxy. Required - access: proxy - # org id. will default to orgId 1 if not specified - orgId: 1 - # url - url: http://localhost:9090 - # database password, if used - password: - # database user, if used - user: - # database name, if used - database: - # enable/disable basic auth - basicAuth: false - # basic auth username, if used - basicAuthUser: - # basic auth password, if used - basicAuthPassword: - # enable/disable with credentials headers - withCredentials: - # mark as default datasource. Max one per org - isDefault: true - # fields that will be converted to json and stored in json_data - jsonData: - graphiteVersion: "1.1" - tlsAuth: false - tlsAuthWithCACert: false - # json object of data that will be encrypted. - secureJsonData: - tlsCACert: "..." - tlsClientCert: "..." - tlsClientKey: "..." - version: 1 - # allow users to edit datasources from the UI. - editable: true \ No newline at end of file + # name of the datasource. Required + - name: Prometheus + # datasource type. Required + type: prometheus + # access mode. direct or proxy. Required + access: proxy + # org id. will default to orgId 1 if not specified + orgId: 1 + # url + url: http://localhost:9090 + # database password, if used + password: + # database user, if used + user: + # database name, if used + database: + # enable/disable basic auth + basicAuth: false + # basic auth username, if used + basicAuthUser: + # basic auth password, if used + basicAuthPassword: + # enable/disable with credentials headers + withCredentials: + # mark as default datasource. Max one per org + isDefault: true + # fields that will be converted to json and stored in json_data + jsonData: + graphiteVersion: "1.1" + tlsAuth: false + tlsAuthWithCACert: false + # json object of data that will be encrypted. + secureJsonData: + tlsCACert: "..." + tlsClientCert: "..." + tlsClientKey: "..." + version: 1 + # allow users to edit datasources from the UI. + editable: true diff --git a/roles/grafana/molecule/default/verify.yml b/roles/grafana/molecule/default/verify.yml index 41c2100..fd0a907 100644 --- a/roles/grafana/molecule/default/verify.yml +++ b/roles/grafana/molecule/default/verify.yml @@ -11,7 +11,7 @@ - name: "Include default vars" ansible.builtin.include_vars: dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/" - extensions: [ 'yml' ] + extensions: ['yml'] - name: "Check if Grafana is installed" changed_when: false diff --git a/roles/grafana/tasks/dashboards.yml b/roles/grafana/tasks/dashboards.yml index 2c1a7ff..79c0604 100644 --- a/roles/grafana/tasks/dashboards.yml +++ b/roles/grafana/tasks/dashboards.yml @@ -1,7 +1,7 @@ --- - name: "Create dashboard directory" ansible.builtin.file: - path: "{{ dashboard_dir }}" + path: "{{ grafana_dashboard_dir }}" state: directory owner: "{{ grafana_user }}" group: "{{ grafana_group }}" @@ -10,7 +10,7 @@ - name: "Copy dashboard files from source to target" ansible.builtin.copy: src: "{{ item }}" - dest: "{{ dashboard_dir }}/{{ item | basename }}" + dest: "{{ grafana_dashboard_dir }}/{{ item | basename }}" mode: "0644" owner: "{{ grafana_user }}" group: "{{ grafana_group }}" @@ -25,7 +25,7 @@ state: present commit_message: Updated by ansible overwrite: false - path: "{{ dashboard_dir }}/{{ item | basename }}" + path: "{{ grafana_dashboard_dir }}/{{ item | basename }}" with_fileglob: - "{{ dashboard_source_path }}/*.json" diff --git a/roles/grafana/tasks/datasources.yml b/roles/grafana/tasks/datasources.yml index c5a2efe..94025c0 100644 --- a/roles/grafana/tasks/datasources.yml +++ b/roles/grafana/tasks/datasources.yml @@ -1,7 +1,7 @@ --- - name: "Create datasource directory" ansible.builtin.file: - path: "{{ datasource_dir }}" + path: "{{ grafana_datasource_dir }}" state: directory owner: "{{ grafana_user }}" group: "{{ grafana_group }}" @@ -10,7 +10,7 @@ - name: "Configure | provision datasources for Grafana" ansible.builtin.copy: src: "{{ datasource_source_path }}/{{ item | basename }}" - dest: "{{ datasource_dir }}/{{ item | basename }}" + dest: "{{ grafana_datasource_dir }}/{{ item | basename }}" owner: "{{ grafana_user }}" group: "{{ grafana_group }}" mode: "0660" diff --git a/roles/grafana/tasks/install.yml b/roles/grafana/tasks/install.yml index e79e378..0f7d33d 100644 --- a/roles/grafana/tasks/install.yml +++ b/roles/grafana/tasks/install.yml @@ -37,9 +37,9 @@ group: "{{ grafana_group }}" mode: '0775' with_items: - - "{{ log_dir }}" - - "{{ data_dir }}" - - "{{ plugins_dir }}" + - "{{ grafana_log_dir }}" + - "{{ grafana_data_dir }}" + - "{{ grafana_plugins_dir }}" - name: "Download Grafana DEB package" ansible.builtin.get_url: @@ -48,12 +48,12 @@ owner: "{{ grafana_user }}" group: "{{ grafana_group }}" mode: "0644" - register: package_tmp + register: grafana_package_tmp - name: "Install DEB package" notify: "(Re)start and enable Grafana" ansible.builtin.apt: - deb: "{{ package_tmp.dest }}" + deb: "{{ grafana_package_tmp.dest }}" state: present update_cache: true diff --git a/roles/grafana/tasks/plugins.yml b/roles/grafana/tasks/plugins.yml index 4572019..96af00c 100644 --- a/roles/grafana/tasks/plugins.yml +++ b/roles/grafana/tasks/plugins.yml @@ -1,7 +1,7 @@ --- - name: "Create plugin directory" ansible.builtin.file: - path: "{{ plugins_dir }}" + path: "{{ grafana_plugins_dir }}" state: directory owner: "{{ grafana_user }}" group: "{{ grafana_group }}" @@ -11,6 +11,6 @@ community.grafana.grafana_plugin: name: "{{ plugin.name }}" version: "{{ plugin.version }}" - grafana_plugins_dir: "{{ plugins_dir }}" + grafana_plugins_dir: "{{ grafana_plugins_dir }}" state: "{{ plugin.state | default('present') }}" notify: "(Re)start and enable Grafana" diff --git a/roles/grafana/templates/grafana-server.env.j2 b/roles/grafana/templates/grafana-server.env.j2 index ced8b6c..0abd646 100644 --- a/roles/grafana/templates/grafana-server.env.j2 +++ b/roles/grafana/templates/grafana-server.env.j2 @@ -4,9 +4,9 @@ GRAFANA_GROUP=grafana GRAFANA_HOME=/usr/share/grafana -LOG_DIR={{ log_dir }} +LOG_DIR={{ grafana_log_dir }} -DATA_DIR={{ data_dir }} +DATA_DIR={{ grafana_data_dir }} MAX_OPEN_FILES=10000 @@ -16,7 +16,7 @@ CONF_FILE=/etc/grafana/grafana.ini RESTART_ON_UPGRADE=true -PLUGINS_DIR={{ plugins_dir }} +PLUGINS_DIR={{ grafana_plugins_dir }} PROVISIONING_CFG_DIR=/etc/grafana/provisioning