use ansible instead of docker compose

Mainly so everything can be on the same Docker network
main
Alpha Chen 2 years ago
parent 58c05cbe00
commit 2ce25ecc08
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -19,16 +19,16 @@
dest: /mnt/lotus-land-story/caddy/Caddyfile
mode: "0644"
- name: Run caddy
community.docker.docker_compose:
project_name: caddy
remove_orphans: true
definition:
version: "3.3"
services:
caddy:
- name: Create Caddy volume
community.docker.docker_volume:
name: caddy
- name: Run Caddy
community.docker.docker_container:
# recreate: true
# restart: true
name: caddy
image: caddy:2
container_name: caddy
ports:
- "80:80"
- "443:443"
@ -37,11 +37,11 @@
- /mnt/lotus-land-story/caddy/Caddyfile:/etc/caddy/Caddyfile
- /mnt/lotus-land-story/caddy/data:/data
- caddy-config:/config
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
caddy-config:
restart_policy: unless-stopped
networks:
- name: lotus_land_story
etc_hosts:
host.docker.internal: host-gateway
handlers:
- name: Import restarts

@ -45,12 +45,6 @@
- docker-compose-plugin
update_cache: true
- name: Install Loki Docker driver
community.docker.docker_plugin:
plugin_name: grafana/loki-docker-driver
alias: loki
state: enable
- name: Create Docker volume location
ansible.builtin.file:
path: /mnt/lotus-land-story/docker
@ -77,6 +71,10 @@
mode: "0644"
notify: Restart docker
- name: Create docker network
community.docker.docker_network:
name: lotus_land_story
handlers:
- name: Import restarts
ansible.builtin.import_tasks: restarts.yml

@ -1,5 +1,7 @@
- name: Set up Grafana
hosts: lotus-land-story
vars_files:
- vars.yml
tasks:
- name: Create Grafana dir
@ -32,7 +34,7 @@
type: prometheus
# Access mode - proxy (server in the UI) or direct (browser in the UI).
access: proxy
url: http://host.docker.internal:9090
url: http://prometheus:9090
jsonData:
httpMethod: POST
manageAlerts: true
@ -40,25 +42,26 @@
prometheusVersion: 2.37.0
mode: "0644"
- name: Create Grafana volume
community.docker.docker_volume:
name: grafana
- name: Run Grafana
community.docker.docker_compose:
project_name: grafana
remove_orphans: true
definition:
version: "3.3"
services:
grafana:
image: grafana/grafana-oss:latest
community.docker.docker_container:
# recreate: true
# restart: true
name: grafana
image: grafana/grafana-oss:9.2.15
ports:
- "3000:3000"
volumes:
- /mnt/lotus-land-story/grafana/grafana.ini:/etc/grafana/grafana.ini
- /mnt/lotus-land-story/grafana/provisioning:/etc/grafana/provisioning
- grafana:/var/lib/grafana
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
grafana:
restart_policy: unless-stopped
networks:
- name: lotus_land_story
etc_hosts:
host.docker.internal: host-gateway
# vim: ft=yaml.ansible

@ -15,13 +15,15 @@
- name: Loki
type: loki
access: proxy
url: http://host.docker.internal:3100
url: http://loki:3100
mode: "0644"
- name: Create Loki config dirs
ansible.builtin.file:
path: /mnt/lotus-land-story/loki/{{ item }}
state: directory
owner: 10001
group: 10001
mode: "0755"
loop:
- config
@ -29,13 +31,11 @@
- name: Configure Loki
ansible.builtin.copy:
dest: /mnt/lotus-land-story/loki/config/config.yml
dest: /mnt/lotus-land-story/loki/config/loki.yml
content: |
auth_enabled: false
server:
http_listen_port: 3100
common:
path_prefix: /loki
storage:
@ -46,7 +46,6 @@
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: 2020-10-24
@ -56,32 +55,78 @@
index:
prefix: index_
period: 24h
storage_config:
filesystem:
directory: /data
ruler:
alertmanager_url: http://localhost:9093
owner: 10001
group: 10001
mode: "0644"
# https://github.com/grafana/loki/issues/2361
- name: Configure Promtail
ansible.builtin.copy:
dest: /mnt/lotus-land-story/loki/config/promtail.yml
content: |
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://loki:3100/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log
- job_name: docker
docker_sd_configs:
- host: unix:///var/run/docker.sock
refresh_interval: 5s
relabel_configs:
- source_labels: ['__meta_docker_container_name']
regex: '/(.*)'
target_label: 'container'
mode: "0644"
- name: Run Loki
community.docker.docker_compose:
project_name: loki
remove_orphans: true
definition:
version: "3.3"
services:
loki:
community.docker.docker_container:
# recreate: true
# restart: true
name: loki
image: grafana/loki:2.8.0
ports:
- "3100:3100"
command: -config.file=/mnt/config/config.yml
command: -config.file=/mnt/config/loki.yml
volumes:
- /mnt/lotus-land-story/loki/config:/mnt/config
- /mnt/lotus-land-story/loki/data:/data
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
restart_policy: unless-stopped
networks:
- name: lotus_land_story
etc_hosts:
host.docker.internal: host-gateway
- name: Run Promtail
community.docker.docker_container:
# recreate: true
# restart: true
name: promtail
image: grafana/promtail:2.8.0
command: -config.file=/mnt/config/promtail.yml
volumes:
- /var/log:/var/log
- /var/run/docker.sock:/var/run/docker.sock
- /mnt/lotus-land-story/loki/config:/mnt/config
restart_policy: unless-stopped
networks:
- name: lotus_land_story
etc_hosts:
host.docker.internal: host-gateway
# vim: ft=yaml.ansible

@ -89,6 +89,7 @@
when: "'prometheus' not in postgres_info.roles"
- import_playbook: grafana.yml # noqa: name[play]
- import_playbook: loki.yml # noqa: name[play]
- import_playbook: miniflux.yml # noqa: name[play]
- import_playbook: caddy.yml # noqa: name[play]

@ -46,26 +46,25 @@
- vars.yml
tasks:
- name: Run miniflux
community.docker.docker_compose:
project_name: miniflux
remove_orphans: true
definition:
version: "3.3"
services:
miniflux:
image: miniflux/miniflux:latest
- name: Run Miniflux
community.docker.docker_container:
# recreate: true
# restart: true
name: miniflux
image: miniflux/miniflux:2.0.43
ports:
- "8080:8080"
environment:
- DATABASE_URL=postgres://miniflux:{{ miniflux_db_password }}@host.docker.internal/miniflux
- RUN_MIGRATIONS=1
- CREATE_ADMIN=1
- ADMIN_USERNAME=alpha
- ADMIN_PASSWORD={{ miniflux_password }}
- BASE_URL=https://rss.{{ domain }}
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
env:
DATABASE_URL: postgres://miniflux:{{ miniflux_db_password }}@host.docker.internal/miniflux
RUN_MIGRATIONS: "1"
CREATE_ADMIN: "1"
ADMIN_USERNAME: alpha
ADMIN_PASSWORD: "{{ miniflux_password }}"
BASE_URL: https://rss.{{ domain }}
restart_policy: unless-stopped
networks:
- name: lotus_land_story
etc_hosts:
host.docker.internal: host-gateway
# vim: ft=yaml.ansible

@ -34,7 +34,7 @@
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'prometheus'
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
@ -42,38 +42,42 @@
static_configs:
- targets: ['host.docker.internal:9100']
- job_name: 'docker'
- job_name: docker
static_configs:
- targets: ['host.docker.internal:9323']
- job_name: caddy
static_configs:
- targets: ['host.docker.internal:2019']
- targets: ['caddy:2019']
- job_name: 'grafana'
- job_name: grafana
static_configs:
- targets: ['host.docker.internal:3000']
- targets: ['grafana:3000']
- job_name: 'postgres'
- job_name: postgres
static_configs:
- targets: ['host.docker.internal:9187']
mode: "0644"
- name: Create Prometheus volume
community.docker.docker_volume:
name: prometheus
- name: Run Prometheus
community.docker.docker_compose:
project_name: prometheus
remove_orphans: true
definition:
version: "3.3"
services:
prometheus:
image: prom/prometheus:latest
community.docker.docker_container:
# recreate: true
# restart: true
name: prometheus
image: prom/prometheus:v2.43.0
ports:
- "9090:9090"
volumes:
- /mnt/lotus-land-story/prometheus:/etc/prometheus
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
- prometheus:/prometheus
restart_policy: unless-stopped
networks:
- name: lotus_land_story
etc_hosts:
host.docker.internal: host-gateway
# vim: ft=yaml.ansible

@ -2,18 +2,18 @@
metrics
}
loki.{{ domain }} {
reverse_proxy loki:3100
}
rss.{{ domain }} {
reverse_proxy host.docker.internal:8080
reverse_proxy miniflux:8080
}
prometheus.{{ domain }} {
reverse_proxy host.docker.internal:9090
reverse_proxy prometheus:9090
}
grafana.{{ domain }} {
reverse_proxy host.docker.internal:3000
}
loki.{{ domain }} {
reverse_proxy host.docker.internal:3100
reverse_proxy grafana:3000
}

@ -1,8 +1,4 @@
{
"data-root": "/mnt/lotus-land-story/docker",
"metrics-addr": "{{ docker_ip.address }}:9323",
"log-driver": "loki",
"log-opts": {
"loki-url": "http://localhost:3100/loki/api/v1/push"
}
"metrics-addr": "{{ docker_ip.address }}:9323"
}

Loading…
Cancel
Save