ctucx.git: ansible-configs

My personal ansible roles and playbooks [deprecated in favor of nixos]

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
---

- 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)