|
| 1 | +--- |
| 2 | +- name: Skip public Grafana on non-map hosts |
| 3 | + ansible.builtin.meta: end_role |
| 4 | + when: inventory_hostname != "map-ffsh" |
| 5 | + |
| 6 | +- name: Install prerequisites for Grafana repository |
| 7 | + ansible.builtin.apt: |
| 8 | + name: gnupg |
| 9 | + state: present |
| 10 | + |
| 11 | +- name: Create APT keyrings directory |
| 12 | + ansible.builtin.file: |
| 13 | + path: /etc/apt/keyrings |
| 14 | + state: directory |
| 15 | + owner: root |
| 16 | + group: root |
| 17 | + mode: "0755" |
| 18 | + |
| 19 | +- name: Download Grafana repository signing key |
| 20 | + ansible.builtin.get_url: |
| 21 | + url: "{{ grafana_public_apt_key_url }}" |
| 22 | + dest: /tmp/grafana-public.gpg.key |
| 23 | + mode: "0644" |
| 24 | + |
| 25 | +- name: Convert Grafana repository signing key |
| 26 | + ansible.builtin.command: |
| 27 | + cmd: "gpg --dearmor --output {{ grafana_public_apt_keyring }} /tmp/grafana-public.gpg.key" |
| 28 | + creates: "{{ grafana_public_apt_keyring }}" |
| 29 | + |
| 30 | +- name: Configure Grafana APT repository |
| 31 | + ansible.builtin.apt_repository: |
| 32 | + repo: "{{ grafana_public_apt_repository }}" |
| 33 | + filename: grafana-public |
| 34 | + state: present |
| 35 | + update_cache: true |
| 36 | + |
| 37 | +- name: Install Grafana |
| 38 | + ansible.builtin.apt: |
| 39 | + name: grafana |
| 40 | + state: present |
| 41 | + |
| 42 | +- name: Ensure Grafana service is enabled and running |
| 43 | + ansible.builtin.systemd: |
| 44 | + name: grafana-server |
| 45 | + enabled: true |
| 46 | + state: started |
| 47 | + |
| 48 | +- name: Configure Grafana public instance |
| 49 | + ansible.builtin.template: |
| 50 | + src: grafana.ini.j2 |
| 51 | + dest: /etc/grafana/grafana.ini |
| 52 | + owner: root |
| 53 | + group: grafana |
| 54 | + mode: "0640" |
| 55 | + notify: Restart Grafana |
| 56 | + |
| 57 | +- name: Ensure nginx vhost directory exists |
| 58 | + ansible.builtin.file: |
| 59 | + path: "{{ grafana_public_nginx_sites_available_dir }}" |
| 60 | + state: directory |
| 61 | + owner: root |
| 62 | + group: root |
| 63 | + mode: "0755" |
| 64 | + |
| 65 | +- name: Configure Grafana nginx vhost |
| 66 | + ansible.builtin.template: |
| 67 | + src: grafana.conf.j2 |
| 68 | + dest: "{{ grafana_public_nginx_sites_available_dir }}/{{ grafana_public_domain | replace('.', '-') }}.conf" |
| 69 | + owner: root |
| 70 | + group: root |
| 71 | + mode: "0644" |
| 72 | + notify: |
| 73 | + - Reload nginx |
| 74 | + |
| 75 | +- name: Enable Grafana nginx vhost |
| 76 | + ansible.builtin.file: |
| 77 | + src: "{{ grafana_public_nginx_sites_available_dir }}/{{ grafana_public_domain | replace('.', '-') }}.conf" |
| 78 | + dest: "{{ grafana_public_nginx_sites_enabled_dir }}/{{ grafana_public_domain | replace('.', '-') }}.conf" |
| 79 | + state: link |
| 80 | + force: true |
| 81 | + |
| 82 | +- name: Validate nginx configuration |
| 83 | + ansible.builtin.command: nginx -t |
| 84 | + changed_when: false |
| 85 | + notify: |
| 86 | + - Reload nginx |
0 commit comments