Skip to content

Commit

Permalink
Merge branch 'ansible-collections:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNtReal authored Nov 9, 2023
2 parents 6f65946 + ff49e95 commit 8e1ab84
Show file tree
Hide file tree
Showing 26 changed files with 199 additions and 65 deletions.
6 changes: 1 addition & 5 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
.github

# Repo maintainers, and goverance team (like Anisble's @ansible-commit-external)
* @rrey @seuf @gundalow-collections/community-goverance-team
* @rrey @seuf

# or possibly, we may want to define teams at the org level.
# * @gundalow-collections/grafana-maintainers

# Example of maintainer of just a single plugin
#grafana/plugins/modules/grafana_plugin.py @someone-else


.github/ @gundalow
8 changes: 4 additions & 4 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python_version: ["3.9"]
python_version: ["3.10"]
ansible_version: ["stable-2.13", "stable-2.14", "devel"]
steps:
- name: Perform testing
Expand All @@ -29,7 +29,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python_version: ["3.9"]
python_version: ["3.10"]
ansible_version: ["stable-2.13", "stable-2.14", "devel"]
steps:
- name: Perform testing
Expand All @@ -45,9 +45,9 @@ jobs:
strategy:
fail-fast: false
matrix:
grafana_version: ["9.2.6", "8.5.15", "7.5.16"]
grafana_version: ["9.5.13", "8.5.27", "10.2.0"]
ansible_version: ["stable-2.13", "stable-2.14", "devel"]
python_version: ["3.9"]
python_version: ["3.10"]
services:
grafana:
image: grafana/grafana:${{ matrix.grafana_version }}
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ Grafana Collection Release Notes
.. contents:: Topics


v1.6.1
======

Minor Changes
-------------

- Bump version of Python used in tests to 3.10
- Enable datasource option `time_interval` for prometheus
- Fix documentation url for Ansible doc website
- Now testing against Grafana 9.5.13, 8.5.27, 10.2.0

Bugfixes
--------

- Fix error with datasources configured without basicAuth
- grafana_folder, fix an issue during delete (starting Grafana 9.3)

v1.6.0
======

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Click on the name of a plugin or module to view that content's documentation:
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: ["9.2.6", "8.5.15", "7.5.16"]
grafana_version: ["9.5.13", "8.5.27", "10.2.0"]
```

## Installation and Usage
Expand Down
16 changes: 16 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,19 @@ releases:
name: grafana_organization_user
namespace: ''
release_date: '2023-02-19'
1.6.1:
changes:
bugfixes:
- Fix error with datasources configured without basicAuth
- grafana_folder, fix an issue during delete (starting Grafana 9.3)
minor_changes:
- Bump version of Python used in tests to 3.10
- Enable datasource option `time_interval` for prometheus
- Fix documentation url for Ansible doc website
- Now testing against Grafana 9.5.13, 8.5.27, 10.2.0
fragments:
- 285_fix_doc.yml
- 294-bump-grafana-version.yml
- 300_datasource_prometheus_time_interval.yml
- fix-316.yml
release_date: '2023-11-05'
6 changes: 6 additions & 0 deletions changelogs/fragments/285_fix_doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

minor_changes:
- Fix documentation url for Ansible doc website

...
5 changes: 5 additions & 0 deletions changelogs/fragments/294-bump-grafana-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
minor_changes:
- Bump version of Python used in tests to 3.10
- Now testing against Grafana 9.5.13, 8.5.27, 10.2.0
bugfixes:
- grafana_folder, fix an issue during delete (starting Grafana 9.3)
7 changes: 7 additions & 0 deletions changelogs/fragments/318-org_users_by_org_name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

minor_changes:
- Add parameter `org_name` to `grafana_organization_user`

trivial:
- Add tests for new `grafana_organization_user`-parameter `org_name`
4 changes: 4 additions & 0 deletions changelogs/fragments/321-action-groups-org-users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

bugfixes:
- Add `grafana_organiazion_user` to `action_groups.grafana`
2 changes: 2 additions & 0 deletions changelogs/fragments/fix-316.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Fix error with datasources configured without basicAuth
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: community
name: grafana
version: 1.6.0
version: 1.6.1
readme: README.md
authors:
- Rémi REY (@rrey)
Expand Down
2 changes: 1 addition & 1 deletion hacking/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.28.0
requests==2.31.0
17 changes: 9 additions & 8 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
requires_ansible: '>=2.9.0'
action_groups:
grafana:
- grafana_dashboard
- grafana_datasource
- grafana_folder
- grafana_notification_channel
- grafana_organization
- grafana_plugin
- grafana_team
- grafana_user
- grafana_dashboard
- grafana_datasource
- grafana_folder
- grafana_notification_channel
- grafana_organization
- grafana_organization_user
- grafana_plugin
- grafana_team
- grafana_user
2 changes: 1 addition & 1 deletion plugins/modules/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
grafana_api_key: "{{ grafana_api_key }}"
folder: zabbix
dashboard_id: 6098
dashbord_revision: 1
dashboard_revision: 1
- name: Import Grafana dashboard zabbix
community.grafana.grafana_dashboard:
Expand Down
10 changes: 7 additions & 3 deletions plugins/modules/grafana_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@
(index name), C(mysql) or C(postgres).
required: false
type: str
default: ''
user:
description:
- The datasource login user for influxdb datasources.
type: str
default: ''
password:
description:
- The datasource password.
- Stored as secure data, see C(enforce_secure_data) and notes!
type: str
default: ''
basic_auth_user:
description:
- The datasource basic auth user.
Expand Down Expand Up @@ -181,6 +184,7 @@
- Monthly
- Yearly
type: str
default: ''
tsdb_version:
description:
- The opentsdb version.
Expand Down Expand Up @@ -281,7 +285,6 @@
aws_custom_metrics_namespaces:
description:
- Namespaces of Custom Metrics for CloudWatch datasource type
default: ''
required: false
type: str
azure_cloud:
Expand Down Expand Up @@ -511,7 +514,7 @@

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import quote
from ansible.module_utils.urls import fetch_url, url_argument_spec, basic_auth_header
from ansible.module_utils.urls import fetch_url, basic_auth_header
from ansible_collections.community.grafana.plugins.module_utils import base


Expand All @@ -533,7 +536,8 @@ def compare_datasources(new, current, compareSecureData=True):
if 'readOnly' in current:
del current['readOnly']
if current['basicAuth'] is False:
del current['basicAuthUser']
if 'basicAuthUser' in current:
del current['basicAuthUser']
if 'password' in current:
del current['password']
if 'basicAuthPassword' in current:
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/grafana_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ def _send_request(self, url, data=None, headers=None, method="GET"):
error_msg = resp.read()['message']
self._module.fail_json(failed=True, msg=error_msg)
elif status_code == 200:
return self._module.from_json(resp.read())
# XXX: Grafana folders endpoint stopped sending back json in response for delete operations
# see https://github.com/grafana/grafana/issues/77673
response = resp.read() or "{}"
return self._module.from_json(response)
self._module.fail_json(failed=True, msg="Grafana Folders API answered with HTTP %d" % status_code)

def get_version(self):
Expand Down
22 changes: 21 additions & 1 deletion plugins/modules/grafana_organization_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
default: 1
description:
- Organization ID.
- Mutually exclusive with `org_name`.
org_name:
type: str
description:
- Organization name.
- Mutually exclusive with `org_id`.
extends_documentation_fragment:
- community.grafana.basic_auth
Expand Down Expand Up @@ -156,6 +162,12 @@ def _api_call(self, method, path, payload):
data = json.dumps(payload)
return fetch_url(self._module, self.grafana_url + '/api/' + path, headers=self.headers, method=method, data=data)

def _organization_by_name(self, org_name):
r, info = self._api_call('GET', 'orgs/name/%s' % org_name, None)
if info['status'] != 200:
raise GrafanaAPIException("Unable to retrieve organization: %s" % info)
return json.loads(to_text(r.read()))

def _organization_users(self, org_id):
r, info = self._api_call('GET', 'orgs/%d/users' % org_id, None)
if info['status'] != 200:
Expand All @@ -178,7 +190,7 @@ def _remove_organization_user(self, org_id, user_id):

def _organization_user_by_login(self, org_id, login):
for user in self._organization_users(org_id):
if user['name'] == login or user['email'] == login:
if login in (user['login'], user['email']):
return user

def create_or_update_user(self, org_id, login, role):
Expand Down Expand Up @@ -232,12 +244,16 @@ def main():
argument_spec.pop('grafana_api_key')
argument_spec.update(
org_id=dict(type='int', default=1),
org_name=dict(type='str'),
login=dict(type='str', required=True),
role=dict(type='str', choices=['viewer', 'editor', 'admin'], default='viewer'),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=False,
mutually_exclusive=[
('org_id', 'org_name'),
],
required_if=[
['state', 'present', ['role']],
]
Expand All @@ -246,6 +262,10 @@ def main():
org_id = module.params['org_id']
login = module.params['login']
iface = GrafanaOrganizationUserInterface(module)
if module.params['org_name']:
org_name = module.params['org_name']
organization = iface._organization_by_name(org_name)
org_id = organization['id']
if module.params['state'] == 'present':
role = module.params['role'].capitalize()
result = iface.create_or_update_user(org_id, login, role)
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/targets/grafana_dashboard/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- block:
- include: dashboard-from-url.yml
- include: delete-dashboard.yml
- include: dashboard-from-id.yml
- include: dashboard-from-file.yml
- include: dashboard-export.yml
- include: dashboard-folder-destination.yml
- include_tasks: dashboard-from-url.yml
- include_tasks: delete-dashboard.yml
- include_tasks: dashboard-from-id.yml
- include_tasks: dashboard-from-file.yml
- include_tasks: dashboard-export.yml
- include_tasks: dashboard-folder-destination.yml
22 changes: 11 additions & 11 deletions tests/integration/targets/grafana_datasource/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---

- block:
- include: errors.yml
- include: elastic.yml
- include: influx.yml
- include: postgres.yml
- include: cloudwatch.yml
- include: thruk.yml
- include: loki.yml
- include: zabbix.yml
- include: redis.yml
- include: azure.yml
- include: uid.yml
- include_tasks: errors.yml
- include_tasks: elastic.yml
- include_tasks: influx.yml
- include_tasks: postgres.yml
- include_tasks: cloudwatch.yml
- include_tasks: thruk.yml
- include_tasks: loki.yml
- include_tasks: zabbix.yml
- include_tasks: redis.yml
- include_tasks: azure.yml
- include_tasks: uid.yml

...
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- block:
- include: dingding.yml
- include: discord.yml
- include: email.yml
- include: googlechat.yml
- include: hipchat.yml
- include: kafka.yml
# - include: line.yml
- include: teams.yml
- include: opsgenie.yml
- include: pagerduty.yml
- include: prometheus.yml
- include: pushover.yml
- include: sensu.yml
- include: slack-and-beyond.yml
- include: telegram.yml
# - include: threema.yml
- include: victorops.yml
- include: webhook.yml
- include_tasks: dingding.yml
- include_tasks: discord.yml
- include_tasks: email.yml
- include_tasks: googlechat.yml
- include_tasks: hipchat.yml
- include_tasks: kafka.yml
# - include_tasks: line.yml
- include_tasks: teams.yml
- include_tasks: opsgenie.yml
- include_tasks: pagerduty.yml
- include_tasks: prometheus.yml
- include_tasks: pushover.yml
- include_tasks: sensu.yml
- include_tasks: slack-and-beyond.yml
- include_tasks: telegram.yml
# - include_tasks: threema.yml
- include_tasks: victorops.yml
- include_tasks: webhook.yml
Loading

0 comments on commit 8e1ab84

Please sign in to comment.