Alpha Chen 2 years ago
parent 012f7cd6cf
commit 82e7d01f9f
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -28,8 +28,10 @@ task terraform: "terraform.tfvars" do
end end
desc "" desc ""
task ansible: "vars.yml" do task :ansible, %i[ playbook ] => "vars.yml" do |_, args|
sh "ansible-playbook main.yml" playbook = args.fetch(:playbook, "main")
sh "ansible-playbook #{playbook}.yml"
end end
task "terraform.tfvars" do |t| task "terraform.tfvars" do |t|
@ -38,14 +40,21 @@ end
task "vars.yml" do |t| task "vars.yml" do |t|
linode_volume = `terraform output -raw lotus_land_story_volume` linode_volume = `terraform output -raw lotus_land_story_volume`
miniflux_db_password = `op read op://Private/Miniflux/db_password`.strip miniflux_db_password = `op read "op://Private/Miniflux/db password"`.strip
miniflux_password = `op read op://Private/Miniflux/password`.strip miniflux_password = `op read op://Private/Miniflux/password`.strip
prometheus_linode_api_token = `op read "op://Private/lotus-land-story/prometheus/linode api token"`.strip
File.write(t.name, YAML.dump({ File.write(t.name, YAML.dump({
domain: DOMAIN, "domain" => DOMAIN,
linode_volume:, "linode_volume" => linode_volume,
miniflux_db_password:, "prometheus" => {
miniflux_password:, "linode_api_token" => prometheus_linode_api_token,
}.transform_keys(&:to_s))) },
"miniflux" => {
"db_password" => miniflux_db_password,
"password" => miniflux_password,
},
}))
end end
task default: %i[ terraform ansible ] task default: %i[ terraform ansible ]

@ -32,6 +32,7 @@
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
- "443:443/udp"
- "2019:2019" - "2019:2019"
volumes: volumes:
- /mnt/lotus-land-story/caddy/Caddyfile:/etc/caddy/Caddyfile - /mnt/lotus-land-story/caddy/Caddyfile:/etc/caddy/Caddyfile

@ -21,6 +21,7 @@
disable_total_stats = false disable_total_stats = false
[server] [server]
domain = grafana.{{ domain }} domain = grafana.{{ domain }}
http_addr = 0.0.0.0
mode: "0644" mode: "0644"
- name: Provision Prometheus - name: Provision Prometheus
@ -52,8 +53,8 @@
# restart: true # restart: true
name: grafana name: grafana
image: grafana/grafana-oss:9.2.15 image: grafana/grafana-oss:9.2.15
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

@ -100,8 +100,6 @@
# restart: true # restart: true
name: loki name: loki
image: grafana/loki:2.8.0 image: grafana/loki:2.8.0
ports:
- "3100:3100"
command: -config.file=/mnt/config/loki.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

@ -17,7 +17,7 @@
community.postgresql.postgresql_user: community.postgresql.postgresql_user:
db: miniflux db: miniflux
name: miniflux name: miniflux
password: "{{ miniflux_db_password }}" password: "{{ miniflux.db_password }}"
notify: Restart postgres notify: Restart postgres
- name: Grant Miniflux access to the db - name: Grant Miniflux access to the db
@ -52,14 +52,12 @@
# restart: true # restart: true
name: miniflux name: miniflux
image: miniflux/miniflux:2.0.43 image: miniflux/miniflux:2.0.43
ports:
- "8080:8080"
env: 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_policy: unless-stopped restart_policy: unless-stopped
networks: networks:

@ -1,5 +1,7 @@
- name: Set up Prometheus - name: Set up Prometheus
hosts: lotus-land-story hosts: lotus-land-story
vars_files:
- vars.yml
tasks: tasks:
- name: Install host exporters - name: Install host exporters
@ -21,56 +23,35 @@
ansible.builtin.file: ansible.builtin.file:
path: /mnt/lotus-land-story/prometheus path: /mnt/lotus-land-story/prometheus
state: directory state: directory
owner: prometheus
group: prometheus
mode: "0755" mode: "0755"
- name: Prometheus config - name: Prometheus config
ansible.builtin.copy: ansible.builtin.template:
dest: /mnt/lotus-land-story/prometheus/prometheus.yml dest: /mnt/lotus-land-story/prometheus/prometheus.yml
content: | src: templates/prometheus.yml
global: owner: prometheus
# Attach these labels to any time series or alerts when communicating with group: prometheus
# external systems (federation, remote storage, Alertmanager). mode: "0600"
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: node
static_configs:
- targets: ['host.docker.internal:9100']
- job_name: docker
static_configs:
- targets: ['host.docker.internal:9323']
- job_name: caddy
static_configs:
- targets: ['caddy:2019']
- job_name: grafana
static_configs:
- targets: ['grafana:3000']
- job_name: postgres
static_configs:
- targets: ['host.docker.internal:9187']
mode: "0644"
- name: Create Prometheus volume - name: Create Prometheus volume
community.docker.docker_volume: community.docker.docker_volume:
name: prometheus name: prometheus
- name: Get prometheus user info
ansible.builtin.user:
name: prometheus
register: prometheus_user
- name: Run Prometheus - name: Run Prometheus
community.docker.docker_container: community.docker.docker_container:
# recreate: true # recreate: true
# restart: true # restart: true
name: prometheus name: prometheus
image: prom/prometheus:v2.43.0 image: prom/prometheus:v2.43.0
ports: user: "{{ prometheus_user.uid }}"
- "9090:9090" groups: "{{ prometheus_user.group }}"
volumes: volumes:
- /mnt/lotus-land-story/prometheus:/etc/prometheus - /mnt/lotus-land-story/prometheus:/etc/prometheus
- prometheus:/prometheus - prometheus:/prometheus

@ -0,0 +1,39 @@
global:
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: node
static_configs:
- targets: ['host.docker.internal:9100']
- job_name: docker
static_configs:
- targets: ['host.docker.internal:9323']
- job_name: caddy
static_configs:
- targets: ['caddy:2019']
- job_name: grafana
static_configs:
- targets: ['grafana:3000']
- job_name: postgres
static_configs:
- targets: ['host.docker.internal:9187']
- job_name: promtail
static_configs:
- targets: ['promtail:9080']
- job_name: linode
linode_sd_configs:
- authorization:
credentials: {{ prometheus.linode_api_token }}
Loading…
Cancel
Save