- name: add grafana GPG apt key apt_key: url: https://packages.grafana.com/gpg.key state: present - block: - name: add grafana repository apt_repository: repo: deb https://packages.grafana.com/oss/deb stable main state: present register: grafana_repo notify: restart grafana - name: update apt cache apt: update_cache: yes cache_valid_time: 3600 when: grafana_repo is changed - name: install grafana package apt: pkg: grafana state: present notify: restart grafana - name: copy grafana config template: src: grafana.ini.j2 dest: /etc/grafana/grafana.ini become: yes notify: restart grafana - name: enable grafana service systemd: name: grafana-server state: started enabled: yes register: grafana_service - name: Configure Nginx for Grafana import_role: name: nginx vars: nginx_config_file: "{{ inventory_hostname }}.conf" nginx_server: name: "{{ inventory_hostname }}" port: 80 locations: - path: "= /" return: code: 301 url: "http://{{ inventory_hostname }}{{ grafana_web_path }}" includes: - "{{ nginx_config_dir }}/{{ inventory_hostname }}.d/*.conf" - name: ensure nginx config directory exists file: path: "{{ nginx_config_dir }}/{{ inventory_hostname }}.d" state: directory - include_role: name: nginx tasks_from: configure vars: nginx_config_file: "{{ inventory_hostname }}.d/grafana.conf" nginx_server: locations: - path: "{{ grafana_web_path }}/" proxy_pass: port: "{{ grafana_port }}" path: /