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

@ -45,12 +45,6 @@
- docker-compose-plugin - docker-compose-plugin
update_cache: true 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 - name: Create Docker volume location
ansible.builtin.file: ansible.builtin.file:
path: /mnt/lotus-land-story/docker path: /mnt/lotus-land-story/docker
@ -77,6 +71,10 @@
mode: "0644" mode: "0644"
notify: Restart docker notify: Restart docker
- name: Create docker network
community.docker.docker_network:
name: lotus_land_story
handlers: handlers:
- name: Import restarts - name: Import restarts
ansible.builtin.import_tasks: restarts.yml ansible.builtin.import_tasks: restarts.yml

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

@ -15,13 +15,15 @@
- name: Loki - name: Loki
type: loki type: loki
access: proxy access: proxy
url: http://host.docker.internal:3100 url: http://loki:3100
mode: "0644" mode: "0644"
- name: Create Loki config dirs - name: Create Loki config dirs
ansible.builtin.file: ansible.builtin.file:
path: /mnt/lotus-land-story/loki/{{ item }} path: /mnt/lotus-land-story/loki/{{ item }}
state: directory state: directory
owner: 10001
group: 10001
mode: "0755" mode: "0755"
loop: loop:
- config - config
@ -29,13 +31,11 @@
- name: Configure Loki - name: Configure Loki
ansible.builtin.copy: ansible.builtin.copy:
dest: /mnt/lotus-land-story/loki/config/config.yml dest: /mnt/lotus-land-story/loki/config/loki.yml
content: | content: |
auth_enabled: false auth_enabled: false
server: server:
http_listen_port: 3100 http_listen_port: 3100
common: common:
path_prefix: /loki path_prefix: /loki
storage: storage:
@ -46,7 +46,6 @@
ring: ring:
kvstore: kvstore:
store: inmemory store: inmemory
schema_config: schema_config:
configs: configs:
- from: 2020-10-24 - from: 2020-10-24
@ -56,32 +55,78 @@
index: index:
prefix: index_ prefix: index_
period: 24h period: 24h
storage_config: storage_config:
filesystem: filesystem:
directory: /data directory: /data
ruler: ruler:
alertmanager_url: http://localhost:9093 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" mode: "0644"
- name: Run Loki - name: Run Loki
community.docker.docker_compose: community.docker.docker_container:
project_name: loki # recreate: true
remove_orphans: true # restart: true
definition: name: loki
version: "3.3"
services:
loki:
image: grafana/loki:2.8.0 image: grafana/loki:2.8.0
ports: ports:
- "3100:3100" - "3100:3100"
command: -config.file=/mnt/config/config.yml command: -config.file=/mnt/config/loki.yml
volumes: volumes:
- /mnt/lotus-land-story/loki/config:/mnt/config - /mnt/lotus-land-story/loki/config:/mnt/config
- /mnt/lotus-land-story/loki/data:/data - /mnt/lotus-land-story/loki/data:/data
restart: unless-stopped restart_policy: unless-stopped
extra_hosts: networks:
- "host.docker.internal:host-gateway" - 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 # vim: ft=yaml.ansible

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

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

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

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

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

Loading…
Cancel
Save