ansible/roles/grafana/tasks/main.yaml

98 lines
2.6 KiB
YAML
Raw Normal View History

2019-12-02 02:40:29 +00:00
---
- name: gather os specific variables
2022-08-31 03:19:06 +00:00
ansible.builtin.include_vars: "{{ lookup('first_found', params) }}"
2019-12-02 02:40:29 +00:00
vars:
2022-08-31 03:19:06 +00:00
params:
2019-12-02 02:40:29 +00:00
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
2019-12-02 02:40:29 +00:00
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- vars
- name: include os specific tasks
2022-08-31 03:19:06 +00:00
ansible.builtin.include_tasks: "{{ lookup('first_found', params) }}"
2019-12-02 02:40:29 +00:00
vars:
2022-08-31 03:19:06 +00:00
params:
2019-12-02 02:40:29 +00:00
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
2019-12-02 02:40:29 +00:00
- "{{ ansible_distribution }}.yaml"
- "default.yaml"
paths:
- tasks
- name: include os family specific tasks
2022-08-31 03:19:06 +00:00
ansible.builtin.include_tasks: "{{ lookup('first_found', params) }}"
vars:
2022-08-31 03:19:06 +00:00
params:
files:
2019-12-02 02:40:29 +00:00
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- tasks
- name: install package
2022-08-31 18:03:18 +00:00
ansible.builtin.package:
2019-12-02 02:40:29 +00:00
name: "{{ grafana_package_name }}"
state: "{{ grafana_package_state }}"
- name: "create {{ grafana_etc_path }}"
2022-08-31 18:03:18 +00:00
ansible.builtin.file:
2019-12-02 02:40:29 +00:00
path: "{{ grafana_etc_path }}"
owner: root
group: root
mode: 0755
- name: configure
2022-08-31 18:03:18 +00:00
ansible.builtin.template:
2019-12-02 02:40:29 +00:00
src: grafana.ini.j2
dest: "{{ grafana_config_path }}"
owner: root
group: "{{ grafana_group }}"
mode: 0640
notify: restart grafana
2020-06-12 21:32:02 +00:00
- name: provision datasources
2022-08-31 18:03:18 +00:00
ansible.builtin.copy:
2020-06-12 21:32:02 +00:00
dest: "{{ grafana_provisioning_path }}/datasources/datasource.yaml"
content: "{{ grafana_datasources | to_nice_yaml }}"
owner: root
group: "{{ grafana_group }}"
mode: 0640
- name: create dashboard directory
2022-08-31 18:03:18 +00:00
ansible.builtin.file:
2020-06-12 21:32:02 +00:00
path: /var/lib/grafana/dashboards
state: directory
owner: "{{ grafana_user }}"
group: "{{ grafana_group }}"
mode: 0755
- name: provision dashboards
2022-08-31 18:03:18 +00:00
ansible.builtin.copy:
2020-06-12 21:32:02 +00:00
dest: "{{ grafana_provisioning_path }}/dashboards/dashboards.yaml"
content: "{{ grafana_dashboards | to_nice_yaml }}"
owner: root
group: "{{ grafana_group }}"
mode: 0640
- name: upload user dashboards
2022-08-31 18:03:18 +00:00
ansible.builtin.copy:
2020-06-12 21:32:02 +00:00
src: "files/grafana/dashboards/{{ item }}"
dest: "/var/lib/grafana/dashboards/{{ item | basename }}"
owner: "{{ grafana_user }}"
group: "{{ grafana_group }}"
mode: 0644
loop: "{{ grafana_dashboard_files | default([]) }}"
2019-12-02 02:40:29 +00:00
- name: manage service
2022-08-31 18:03:18 +00:00
ansible.builtin.service:
2019-12-02 02:40:29 +00:00
name: "{{ grafana_service_name }}"
state: "{{ grafana_service_state }}"
enabled: "{{ grafana_service_enabled }}"
- name: configure nginx
2022-08-31 03:19:06 +00:00
ansible.builtin.include_tasks: nginx.yaml
2019-12-02 02:40:29 +00:00
when: "'nginx' in ansible_play_role_names"