Creating Grafana Alerts using Ansible

I have a set of Alerts rules that needs to be created in Grafana, how do I automate this process using Ansible.
I see we have these 2 Ansible collections related to Grafana:

  1. grafana.grafana
  2. community.grafana

But none of these has any modules for configuring Alerts in Grafana.

Thanks in advance.

Since Grafana alerts can be provisioned either through file or http api, you can achieve the automation with ansible.builtin.copy|template modules or ansible.builtin.uri module.

What i have experience with is provisioning alert rules via http api. For every rule i have two tasks, first create with POST (with expected status code 400 if alert already exists), then update with PUT. There is a space for optimization, i.e. if creating rule returns status code 201 it is not needed to update the rule.

I think the reason there are no roles / plays for managing alerting rules in the collections you posted is that there is not much of a useful abstraction over the Ansible builtin modules. It is really just requesting correct url with correct json body.