Skip to content

Commit ec1e341

Browse files
wip
- pin images - update tfvars - set ansible intepreter - change to tenv for managing terraform
1 parent acbfa19 commit ec1e341

6 files changed

Lines changed: 156 additions & 18 deletions

File tree

.gitignore

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# ETC
2-
.terraform.lock.hcl
3-
dashboard.yml
4-
grafana-config.ini
5-
hosts
6-
node-exporter.json
7-
playbooks/*
8-
prometheus.yml
9-
tfplan
2+
**/dashboard.yml
3+
**/grafana-config.ini
4+
**/hosts
5+
**/node-exporter.json
6+
**/prometheus.yml
107

118
# General
129
.DS_Store
@@ -47,10 +44,7 @@ Temporary Items
4744
crash.log
4845
crash.*.log
4946

50-
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
51-
# password, private keys, and other secrets. These should not be part of version
52-
# control as they are data points which are potentially sensitive and subject
53-
# to change depending on the environment.
47+
# Exclude all .tfvars files
5448
*.tfvars
5549
*.tfvars.json
5650

@@ -61,11 +55,9 @@ override.tf.json
6155
*_override.tf
6256
*_override.tf.json
6357

64-
# Include override files you do wish to add to version control using negated pattern
65-
# !example_override.tf
66-
67-
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
68-
# example: *tfplan*
58+
# Ignore terraform state
59+
.terraform.lock.hcl
60+
tfplan
6961

7062
# Ignore CLI configuration files
7163
.terraformrc

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
terraform 1.9.8
21
python 3.11.10
2+
tenv 3.2.9

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ansible.python.interpreterPath": "${workspaceFolder}/.venv/bin/python"
3+
}

docker-compose.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
services:
2+
nodejs:
3+
image: node:23.1.0-bookworm
4+
working_dir: /app
5+
command: ["node"]
6+
ports:
7+
- "3000:3000"
8+
volumes:
9+
- ./app:/app
10+
depends_on:
11+
- mongodb
12+
- elasticsearch
13+
- redis
14+
deploy:
15+
resources:
16+
limits:
17+
cpus: '1'
18+
memory: 1G
19+
reservations:
20+
memory: 512M
21+
22+
mongodb:
23+
image: mongo:8.0.3-noble
24+
ports:
25+
- "27017:27017"
26+
volumes:
27+
- mongodb_data:/data/db
28+
deploy:
29+
resources:
30+
limits:
31+
cpus: '2'
32+
memory: 2G
33+
reservations:
34+
memory: 1G
35+
36+
elasticsearch:
37+
image: elasticsearch:8.15.3
38+
environment:
39+
- discovery.type=single-node
40+
- xpack.security.enabled=false
41+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
42+
ports:
43+
- "9200:9200"
44+
volumes:
45+
- elasticsearch_data:/usr/share/elasticsearch/data
46+
deploy:
47+
resources:
48+
limits:
49+
cpus: '2'
50+
memory: 2G
51+
reservations:
52+
memory: 1G
53+
54+
redis:
55+
image: redis:7.4.1-bookworm
56+
ports:
57+
- "6379:6379"
58+
volumes:
59+
- redis_data:/data
60+
deploy:
61+
resources:
62+
limits:
63+
cpus: '0.5'
64+
memory: 512M
65+
reservations:
66+
memory: 256M
67+
68+
volumes:
69+
mongodb_data:
70+
elasticsearch_data:
71+
redis_data:

exporter.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
- name: Deploy exporters as containers
3+
hosts: all
4+
gather_facts: false
5+
vars:
6+
exporter_defaults:
7+
node:
8+
image: "prom/node-exporter:latest"
9+
port: 9100
10+
mongodb:
11+
image: "bitnami/mongodb-exporter:latest"
12+
port: 9216
13+
redis:
14+
image: "oliver006/redis_exporter:latest"
15+
port: 9121
16+
17+
tasks:
18+
- name: Set exporter type based on inventory group
19+
ansible.builtin.set_fact:
20+
exporter_type: >-
21+
{%- if inventory_hostname in groups.get('node_exporters', []) -%}
22+
node
23+
{%- elif inventory_hostname in groups.get('mongodb_hosts', []) -%}
24+
mongodb
25+
{%- elif inventory_hostname in groups.get('redis_hosts', []) -%}
26+
redis
27+
{%- endif -%}
28+
29+
- name: Start exporter container
30+
community.docker.docker_container:
31+
name: "{{ exporter_type }}-exporter"
32+
image: "{{ exporter_defaults[exporter_type].image }}"
33+
state: started
34+
restart_policy: unless-stopped
35+
published_ports:
36+
- "{{ exporter_defaults[exporter_type].port }}:{{ exporter_defaults[exporter_type].port }}"
37+
container_default_behavior: no_defaults
38+
command: "{{ container_command | default(omit) }}"
39+
vars:
40+
container_command: >-
41+
{%- if exporter_type == 'mongodb' -%}
42+
--mongodb.uri=mongodb://localhost:{{ service_port }}/
43+
{%- elif exporter_type == 'redis' -%}
44+
--redis.addr=redis://localhost:{{ service_port }}/
45+
{%- endif -%}
46+
when: exporter_type is defined and exporter_type != ''

terraform.tfvars.example

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,30 @@ node_exporter_hosts = [
1111
ssh_port = 22
1212
}
1313
]
14+
service_hosts = [
15+
{
16+
service = "nodejs"
17+
name = "app1"
18+
ip = "192.168.86.250"
19+
port = 3000
20+
ssh_user = "admin"
21+
ssh_port = 22
22+
},
23+
{
24+
service = "mongodb"
25+
name = "mongo1"
26+
ip = "192.168.86.250"
27+
port = 27017
28+
ssh_user = "admin"
29+
ssh_port = 22
30+
},
31+
{
32+
service = "redis"
33+
name = "redis1"
34+
ip = "192.168.86.250"
35+
port = 6379
36+
ssh_user = "admin"
37+
ssh_port = 22
38+
}
39+
]
1440
ssh_private_key_path = "~/.ssh/id_rsa"

0 commit comments

Comments
 (0)