Skip to content

Commit

Permalink
feat(grafana): install grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
alesharik committed Jul 7, 2024
1 parent 9ed3b33 commit 2f43a4f
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
40 changes: 40 additions & 0 deletions roles/grafana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# nginx-proxy
__Tags - `grafana`__

Deploys grafana

### Usage
```yaml
- alesharik.baseinfra.grafana
```
```yaml
grafana:
host: mon.example.com
admin_password: password
```
### Vars
```yaml
grafana:
image: grafana/grafana-oss
version: 11.1.0
```
### Effects
- creates and manages `{{ dir.ansible }}/grafana`
- creates `{{ dir.data }}/grafana`
- deploys docker compose project `grafana`

#### Docker networks
- connect to `nginx-proxy`

### Networking
- exposes 80 port through `nginx-proxy` with host specified in config
- connects to network `nginx-proxy`

### Handlers
- `restart grafana` - restarts registry

### Dependencies
- `bootstrap`
- `docker`
4 changes: 4 additions & 0 deletions roles/grafana/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
grafana:
image: grafana/grafana-oss
version: 11.1.0
6 changes: 6 additions & 0 deletions roles/grafana/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: restart grafana
community.docker.docker_compose_v2:
project_src: "{{ dir.ansible }}/grafana"
state: restarted
tags: grafana
4 changes: 4 additions & 0 deletions roles/grafana/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
dependencies:
- role: alesharik.baseinfra.bootstrap
- role: alesharik.baseinfra.docker
41 changes: 41 additions & 0 deletions roles/grafana/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- name: Create compose dir
ansible.builtin.file:
path: "{{ dir.ansible }}/grafana"
state: directory
mode: 0755
tags: grafana
- name: Create data dir
ansible.builtin.file:
path: "{{ dir.data }}/grafana"
state: directory
mode: 0755
owner: '472'
tags: grafana

- name: Move compose files
ansible.builtin.template:
src: docker-compose.yml
dest: "{{ dir.ansible }}/grafana/docker-compose.yml"
mode: 0755
tags: grafana
notify:
- restart grafana
- name: Move admin password
ansible.builtin.template:
src: admin_password.txt
dest: "{{ dir.ansible }}/grafana/admin_password.txt"
mode: 0755
tags: grafana
notify:
- restart grafana

- name: Start grafana
tags: grafana
community.docker.docker_compose_v2:
project_src: "{{ dir.ansible }}/grafana"
state: present

- name: Make sure handlers are flushed immediately
ansible.builtin.meta: flush_handlers
tags: grafana
1 change: 1 addition & 0 deletions roles/grafana/templates/admin_password.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ grafana.admin_password }}
23 changes: 23 additions & 0 deletions roles/grafana/templates/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.9'
networks:
proxy:
external:
name: nginx-proxy
services:
grafana:
image: "{{ grafana.image }}:{{ grafana.version }}"
restart: always
environment:
VIRTUAL_HOST: "{{ grafana.host }}"
VIRTUAL_PORT: 3000
LETSENCRYPT_HOST: "{{ grafana.host }}"
GF_SECURITY_ADMIN_PASSWORD__FILE: "/run/secrets/admin_password"
volumes:
- "{{ dir.data }}/grafana:/var/lib/grafana"
secrets:
- admin_password
networks:
- proxy
secrets:
admin_password:
file: admin_password.txt

0 comments on commit 2f43a4f

Please sign in to comment.