ansible/roles/grafana/tasks/main.yaml

100 lines
2.6 KiB
YAML
Raw Permalink 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:
dest: "{{ grafana_provisioning_path }}/datasources/ansible.yaml"
2020-06-12 21:32:02 +00:00
content: "{{ grafana_datasources | to_nice_yaml }}"
owner: root
group: "{{ grafana_group }}"
mode: 0640
notify: restart grafana
2020-06-12 21:32:02 +00:00
- 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:
dest: "{{ grafana_provisioning_path }}/dashboards/ansible.yaml"
2020-06-12 21:32:02 +00:00
content: "{{ grafana_dashboards | to_nice_yaml }}"
owner: root
group: "{{ grafana_group }}"
mode: 0640
notify: restart grafana
2020-06-12 21:32:02 +00:00
- name: upload user dashboards
ansible.posix.synchronize:
src: "{{ grafana_user_dashboard_path }}"
dest: "{{ grafana_dashboard_path }}/"
owner: false
group: false
delete: true
notify: restart grafana
2020-06-12 21:32:02 +00:00
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"