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,29 +19,29 @@
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
image: caddy:2 name: caddy
container_name: caddy image: caddy:2
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
- "2019:2019" - "2019:2019"
volumes: volumes:
- /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: ports:
grafana: - "3000:3000"
image: grafana/grafana-oss:latest volumes:
ports: - /mnt/lotus-land-story/grafana/grafana.ini:/etc/grafana/grafana.ini
- "3000:3000" - /mnt/lotus-land-story/grafana/provisioning:/etc/grafana/provisioning
volumes: - grafana:/var/lib/grafana
- /mnt/lotus-land-story/grafana/grafana.ini:/etc/grafana/grafana.ini restart_policy: unless-stopped
- /mnt/lotus-land-story/grafana/provisioning:/etc/grafana/provisioning networks:
- grafana:/var/lib/grafana - name: lotus_land_story
restart: unless-stopped etc_hosts:
extra_hosts: host.docker.internal: host-gateway
- "host.docker.internal:host-gateway"
volumes:
grafana:
# 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" image: grafana/loki:2.8.0
services: ports:
loki: - "3100:3100"
image: grafana/loki:2.8.0 command: -config.file=/mnt/config/loki.yml
ports: volumes:
- "3100:3100" - /mnt/lotus-land-story/loki/config:/mnt/config
command: -config.file=/mnt/config/config.yml - /mnt/lotus-land-story/loki/data:/data
volumes: restart_policy: unless-stopped
- /mnt/lotus-land-story/loki/config:/mnt/config networks:
- /mnt/lotus-land-story/loki/data:/data - name: lotus_land_story
restart: unless-stopped etc_hosts:
extra_hosts: host.docker.internal: host-gateway
- "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: ports:
miniflux: - "8080:8080"
image: miniflux/miniflux:latest env:
ports: DATABASE_URL: postgres://miniflux:{{ miniflux_db_password }}@host.docker.internal/miniflux
- "8080:8080" RUN_MIGRATIONS: "1"
environment: CREATE_ADMIN: "1"
- DATABASE_URL=postgres://miniflux:{{ miniflux_db_password }}@host.docker.internal/miniflux ADMIN_USERNAME: alpha
- RUN_MIGRATIONS=1 ADMIN_PASSWORD: "{{ miniflux_password }}"
- CREATE_ADMIN=1 BASE_URL: https://rss.{{ domain }}
- ADMIN_USERNAME=alpha restart_policy: unless-stopped
- ADMIN_PASSWORD={{ miniflux_password }} networks:
- BASE_URL=https://rss.{{ domain }} - name: lotus_land_story
restart: unless-stopped etc_hosts:
extra_hosts: host.docker.internal: host-gateway
- "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: ports:
prometheus: - "9090:9090"
image: prom/prometheus:latest volumes:
ports: - /mnt/lotus-land-story/prometheus:/etc/prometheus
- "9090:9090" - prometheus:/prometheus
volumes: restart_policy: unless-stopped
- /mnt/lotus-land-story/prometheus:/etc/prometheus networks:
restart: unless-stopped - name: lotus_land_story
extra_hosts: etc_hosts:
- "host.docker.internal:host-gateway" 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