--- - name: "Create directorys needed for provisioning" file: state: directory dest: "{{ item }}" mode: 0755 owner: grafana group: grafana with_items: - /var/lib/grafana - /var/lib/grafana/provisioning - /var/lib/grafana/provisioning/dashboards - /var/lib/grafana/provisioning/datasources notify: "Restart grafana" - name: "Copy dashboards jsons to: /var/lib/grafana/provisioning/dashboards" copy: src: "{{ services.grafana.provisioning.dashboards }}/" dest: /var/lib/grafana/provisioning/dashboards mode: 0755 owner: grafana group: grafana notify: "Restart grafana" - name: "Generate /var/lib/grafana/provisioning/datasources/datasources.yml" template: src: datasources.yml.j2 dest: /var/lib/grafana/provisioning/datasources/datasources.yml mode: 0755 owner: grafana group: grafana notify: "Delete database and restart grafana" - name: "Generate file: /var/lib/grafana/provisioning/dashboards/dashboards.yml" template: src: dashboards.yml.j2 dest: /var/lib/grafana/provisioning/dashboards/dashboards.yml mode: 0755 owner: grafana group: grafana - name: "Collect files in directory: /var/lib/grafana/provisioning/dashboards" find: path: /var/lib/grafana/provisioning/dashboards hidden: yes register: grafana_dashboards_remote check_mode: no changed_when: false - name: "Collect files in local directory: {{ services.grafana.provisioning.dashboards }}" local_action: module: find path: "{{ services.grafana.provisioning.dashboards }}" hidden: yes register: grafana_dashboards_local check_mode: no changed_when: false - name: "Remove unmanaged files in directory: /var/lib/grafana/provisioning/dashboards" file: path: "/var/lib/grafana/provisioning/dashboards/{{ item.path | basename }}" state: absent with_items: - "{{ grafana_dashboards_remote.files }}" notify: "Delete database and restart grafana" when: - (item.path | basename) != "dashboards.yml" and (item.path | basename) not in (grafana_dashboards_local.files | map(attribute="path") | map("basename") | list)