--- - name: Remove grafana when: not grafana_enabled tags: [grafana] block: - name: Ensure that grafana is stopped and disabled ansible.builtin.service: name: grafana-server state: stopped enabled: false - name: Remove the grafana deb packages ansible.builtin.apt: name: "{{ grafana_packages }}" state: absent - name: Install the grafana deb repository ansible.builtin.apt_repository: repo: '{{ grafana_repo }}' state: absent update_cache: true - name: Install grafana when: grafana_enabled tags: [grafana] block: - name: Ensure that the directory were the GPG key is stored exists ansible.builtin.file: dest: /etc/apt/keyrings state: directory mode: "0755" owner: root group: root - name: Install the grafana repo key ansible.builtin.get_url: url: "{{ grafana_repo_key_url }}" dest: "{{ grafana_repo_key_file }}" owner: root group: root mode: "0644" tags: [grafana, grafana_repo_key] - name: Install the grafana repository for Ubuntu ansible.builtin.deb822_repository: name: grafana-com types: [deb] uris: "{{ grafana_repo_url }}" components: "{{ grafana_repo_components }}" suites: "{{ grafana_repo_suites }}" signed_by: "{{ grafana_repo_key_file }}" state: present enabled: true - name: Install the grafana packages ansible.builtin.apt: pkg: "{{ grafana_packages }}" cache_valid_time: 1800 state: "{{ grafana_pkg_state }}" - name: Basic grafana configuration community.general.ini_file: path: /etc/grafana/grafana.ini section: "{{ item.section }}" option: "{{ item.option }}" value: "{{ item.value }}" state: "{{ item.state | default('present') }}" mode: "0440" owner: root group: grafana loop: "{{ grafana_conf }}" notify: Restart grafana tags: [grafana, grafana_conf] - name: Add additional grafana configurations community.general.ini_file: path: /etc/grafana/grafana.ini section: "{{ item.section }}" option: "{{ item.option }}" value: "{{ item.value }}" state: "{{ item.state | default('present') }}" mode: "0440" owner: root group: grafana loop: "{{ grafana_additional_conf }}" notify: Restart grafana tags: [grafana, grafana_conf] - name: Install the grafana LDAP configuration file ansible.builtin.template: src: "{{ item }}.j2" dest: /etc/grafana/{{ item }} mode: "0440" owner: root group: grafana loop: "{{ grafana_ldap_conf_file }}" notify: Restart grafana when: grafana_ldap_auth tags: [grafana, grafana_conf, grafana_ldap] - name: Create the local dashboards directory ansible.builtin.file: dest: /var/lib/grafana/dashboards state: directory mode: "0755" owner: grafana group: grafana - name: Install additional plugins, if any community.grafana.grafana_plugin: name: "{{ item.name }}" state: "{{ item.state | default('present') }}" grafana_repo: "{{ item.repo | default('https://grafana.com/api/plugins') }}" loop: "{{ grafana_additional_plugins }}" tags: [grafana, grafana_plugins] - name: Ensure that grafana is enabled and running ansible.builtin.service: name: grafana-server state: started enabled: true