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

support foldersFromFilesStructure #277

Open
copolycube opened this issue Oct 9, 2024 · 1 comment
Open

support foldersFromFilesStructure #277

copolycube opened this issue Oct 9, 2024 · 1 comment

Comments

@copolycube
Copy link
Contributor

https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards indicate that we can push a structure of dashboards to grafana, but no options in the playbook allows this currently

@copolycube
Copy link
Contributor Author

copolycube commented Dec 13, 2024

workaround : for a dashboards/ directory at the same level of the playbook :

---
- name: Monitoring collector - grafana setup
  hosts: label_monitoring_server
  vars:
    become_user: root
    become: true
    dashboards_dir: /var/lib/grafana/dashboards-git
  roles:
    # # Using grafana collection
    # # https://github.com/grafana/grafana-ansible-collection/tree/main/roles/grafana
    # # https://galaxy.ansible.com/ui/repo/published/grafana/grafana/content/role/grafana/?keywords=

    - role: grafana.grafana.grafana
      vars:
        # Grafana configuration - https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#
        grafana_version: '11.3.1'
        grafana_log:
          level: debug
# [...]
  tasks:
    # https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards
    # Circumvent / until fix https://github.com/grafana/grafana-ansible-collection/issues/277
    - name: Dashboard provider with foldersFromFilesStructure
      become: true
      ignore_errors: True
      block:
        - name: Ensure grafana provisioning dashboard config directory exist
          ansible.builtin.file:
            path: /etc/grafana/provisioning/dashboards
            state: directory
            mode: '0755'

        - name: Generate grafana provisioning dashboards config file git-versionned-dashboards.yml
          ansible.builtin.copy:
            dest: /etc/grafana/provisioning/dashboards/git-versionned-dashboards.yml
            content: |
              apiVersion: 1
              providers:
              -   name: git-versionned
                  folder: 'git-versionned'
                  options:
                      path: {{ dashboards_dir }}
                      foldersFromFilesStructure: true
                  orgId: 1
                  type: file
            mode: '0644'

        - name: Push whole directory of git git-versionned dashboards
          ansible.builtin.copy:
            src: "dashboards/"
            dest: "{{ dashboards_dir }}"
            mode: "0755"
          become: true

        - name: Set privileges on provisioned dashboards
          ansible.builtin.file:
            path: "{{ dashboards_dir }}"
            recurse: true
            owner: "grafana"
            group: "grafana"
            mode: "0640"
          become: true

        - name: Set privileges on provisioned dashboards directory structure
          ansible.builtin.file:
            path: "{{ dashboards_dir }}"
            state: "directory"
            recurse: true
            mode: "0755"
          become: true

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

No branches or pull requests

1 participant