diff --git a/ansible/playbooks/heyer.systems/docker1.yml b/ansible/playbooks/heyer.systems/docker1.yml index f88570b..ca2c678 100644 --- a/ansible/playbooks/heyer.systems/docker1.yml +++ b/ansible/playbooks/heyer.systems/docker1.yml @@ -51,3 +51,8 @@ tags: - booklore - docker-container + + - role: deploy_container_grafana + tags: + - grafana + - docker-container diff --git a/ansible/roles/deploy_container_grafana/defaults/main.yml b/ansible/roles/deploy_container_grafana/defaults/main.yml new file mode 100644 index 0000000..b15432e --- /dev/null +++ b/ansible/roles/deploy_container_grafana/defaults/main.yml @@ -0,0 +1,3 @@ +--- +container_grafana_version: latest +container_grafana_domain: grafana.example.com \ No newline at end of file diff --git a/ansible/roles/deploy_container_grafana/files/.gitkeep b/ansible/roles/deploy_container_grafana/files/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/deploy_container_grafana/handlers/main.yml b/ansible/roles/deploy_container_grafana/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/deploy_container_grafana/meta/main.yml b/ansible/roles/deploy_container_grafana/meta/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/deploy_container_grafana/tasks/main.yml b/ansible/roles/deploy_container_grafana/tasks/main.yml new file mode 100644 index 0000000..67b1701 --- /dev/null +++ b/ansible/roles/deploy_container_grafana/tasks/main.yml @@ -0,0 +1,24 @@ +--- +- name: Ensure data directories exist + ansible.builtin.file: + path: "{{ container_base_dir }}/" + state: directory + mode: '0755' + become: false + +- name: Deploy Docker Compose and .env files + ansible.builtin.template: + src: "{{ item.src }}" + dest: "{{ container_base_dir }}/{{ item.dest }}" + mode: '0644' + loop: + - { src: 'docker-compose.yml.j2', dest: 'docker-compose.yml' } + - { src: '.env.j2', dest: '.env' } + become: false + +- name: Start Container + community.docker.docker_compose_v2: + project_src: "{{ container_base_dir }}" + pull: always + docker_host: "unix:///run/user/1000/docker.sock" + become: false diff --git a/ansible/roles/deploy_container_grafana/templates/.env.j2 b/ansible/roles/deploy_container_grafana/templates/.env.j2 new file mode 100644 index 0000000..090a73b --- /dev/null +++ b/ansible/roles/deploy_container_grafana/templates/.env.j2 @@ -0,0 +1,2 @@ +GRAFANA_VERSION={{ container_grafana_version }} +GRAFANA_DOMAIN={{ container_grafana_domain }} \ No newline at end of file diff --git a/ansible/roles/deploy_container_grafana/templates/docker-compose.yml.j2 b/ansible/roles/deploy_container_grafana/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..a3395eb --- /dev/null +++ b/ansible/roles/deploy_container_grafana/templates/docker-compose.yml.j2 @@ -0,0 +1,32 @@ +--- +services: + grafana: + image: grafana/grafana:${GRAFANA_VERSION} + container_name: grafana + restart: unless-stopped + networks: + traefik: + volumes: + - 'grafana_storage:/var/lib/grafana' + environment: + - GF_SERVER_ROOT_URL=https://${GRAFANA_DOMAIN}/ + - GF_PLUGINS_PREINSTALL=grafana-clock-panel + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.grafana.entrypoints=http" + - "traefik.http.routers.grafana.rule=Host(`${GRAFANA_DOMAIN}`)" + - "traefik.http.middlewares.grafana-https-redirect.redirectscheme.scheme=https" + - "traefik.http.routers.grafana.middlewares=grafana-https-redirect" + - "traefik.http.routers.grafana-secure.entrypoints=https" + - "traefik.http.routers.grafana-secure.rule=Host(`${GRAFANA_DOMAIN}`)" + - "traefik.http.routers.grafana-secure.tls=true" + - "traefik.http.routers.grafana-secure.service=grafana" + - "traefik.http.services.grafana.loadbalancer.server.port=3000" + +volumes: + grafana_storage: {} + +networks: + traefik: + external: true \ No newline at end of file diff --git a/ansible/roles/deploy_container_grafana/vars/main.yml b/ansible/roles/deploy_container_grafana/vars/main.yml new file mode 100644 index 0000000..f1efe20 --- /dev/null +++ b/ansible/roles/deploy_container_grafana/vars/main.yml @@ -0,0 +1 @@ +container_base_dir: /opt/docker/grafana \ No newline at end of file