Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
ansible_python_interpreter: /usr/bin/python3

# role
Expand All @@ -11,3 +12,5 @@ ghcr_token: "{{ lookup('env', 'GHCR_TOKEN') }}"
# node-exporter
node_exporter_image: "prom/node-exporter:v1.8.1"
node_exporter_port: 9100
...

9 changes: 8 additions & 1 deletion ansible/group_vars/app.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---
app_image: "ghcr.io/tysker/cloud_devops_app:0950da9"
app_container_name: "cloud-devops-app"
app_container_port: 5000
app_public_port: 80
app_public_port: 5000

# caddy
caddy_config_dir: "/opt/caddy/config"
caddy_data_dir: "/opt/caddy/data"
caddy_image: "caddy:2.10.0-alpine"
...
2 changes: 2 additions & 0 deletions ansible/group_vars/monitoring.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# prometheus
prometheus_image: "prom/prometheus:v2.52.0"
prometheus_port: 9090
Expand All @@ -8,3 +9,4 @@ prometheus_data_dir: "/opt/prometheus/data"
grafana_image: "grafana/grafana:10.4.3"
grafana_port: 3000
grafana_data_dir: "/opt/grafana/data"
...
2 changes: 2 additions & 0 deletions ansible/playbooks/bootstrap_1.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
- name: Bootstrap all server (initial)
hosts: all
remote_user: root
roles:
- common
- bootstrap_user
...
2 changes: 2 additions & 0 deletions ansible/playbooks/bootstrap_2.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Harden SSH (after devops exists)
hosts: all
remote_user: devops
Expand All @@ -12,3 +13,4 @@
become: true
roles:
- docker
...
8 changes: 8 additions & 0 deletions ansible/playbooks/caddy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Caddy directories for domain certification
hosts: app
remote_user: devops
become: true
roles:
- caddy
...
2 changes: 2 additions & 0 deletions ansible/playbooks/deploy_app.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
- name: Deploy Flask app container
hosts: app
remote_user: devops
gather_facts: true
become: true
roles:
- deploy_app
...
2 changes: 2 additions & 0 deletions ansible/playbooks/monitoring_grafana.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
- name: Deploy Grafana on monitoring server
hosts: monitoring
remote_user: devops
gather_facts: true
become: true
roles:
- grafana
...
2 changes: 2 additions & 0 deletions ansible/playbooks/monitoring_node_exporter.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
- name: Deploy Node Exporter on app and monitoring servers
hosts: app:monitoring
remote_user: devops
gather_facts: true
become: true
roles:
- node_exporter
...
2 changes: 2 additions & 0 deletions ansible/playbooks/monitoring_prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
- name: Deploy Prometheus on monitoring server
hosts: monitoring
gather_facts: true
remote_user: devops
become: true
roles:
- prometheus
...
2 changes: 2 additions & 0 deletions ansible/roles/bootstrap_user/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Ensure devops user exists
ansible.builtin.user:
name: "{{ devops_user }}"
Expand All @@ -19,3 +20,4 @@
user: "{{ devops_user }}"
key: "{{ devops_public_key }}"
state: present
...
34 changes: 34 additions & 0 deletions ansible/roles/caddy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Ensure Caddy directories exist
become: true
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: "0755"
loop:
- "{{ caddy_config_dir }}"
- "{{ caddy_data_dir }}"

- name: Render Caddy configuration
ansible.builtin.template:
src: caddyfile.yml.j2
dest: "/opt/caddy/Caddyfile"
owner: root
group: root
mode: "0644"

- name: Ensure Caddy container is running
community.docker.docker_container:
name: caddy
image: "{{ caddy_image }}"
state: started
restart_policy: unless-stopped
network_mode: host
recreate: true
volumes:
- "/opt/caddy/Caddyfile:/etc/caddy/Caddyfile:ro"
- "{{ caddy_config_dir }}:/config"
- "{{ caddy_data_dir }}:/data"
...
18 changes: 18 additions & 0 deletions ansible/roles/caddy/templates/caddyfile.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(cloud_devops_headers) {
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "no-referrer"
}
}

clouddevopslab.eu, www.clouddevopslab.eu {
import cloud_devops_headers
reverse_proxy 127.0.0.1:5000
}

http://{{ hostvars[inventory_hostname].ansible_host }} {
reverse_proxy 127.0.0.1:5000
}


2 changes: 2 additions & 0 deletions ansible/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
---
- name: Ensure system is reachable
ping:
...
7 changes: 5 additions & 2 deletions ansible/roles/deploy_app/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: (Optional) Login to GHCR
community.docker.docker_login:
registry_url: ghcr.io
Expand All @@ -19,14 +20,16 @@
image: "{{ app_image }}"
state: started
restart_policy: unless-stopped
recreate: true
ports:
- "{{ app_public_port }}:{{ app_container_port }}"
- "127.0.0.1:{{ app_public_port }}:{{ app_container_port }}"

- name: Wait for /health to return 200 on the server
ansible.builtin.uri:
url: "http://localhost/health"
url: "http://127.0.0.1:{{ app_container_port }}/health"
status_code: 200
register: healthcheck
retries: 10
delay: 2
until: healthcheck.status == 200
...
Empty file.
2 changes: 2 additions & 0 deletions ansible/roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Install prerequisites
ansible.builtin.apt:
name:
Expand Down Expand Up @@ -51,3 +52,4 @@
name: "{{ devops_user }}"
groups: docker
append: true
...
2 changes: 2 additions & 0 deletions ansible/roles/grafana/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Ensure Grafana data directory exists
ansible.builtin.file:
path: "{{ grafana_data_dir }}"
Expand All @@ -19,3 +20,4 @@
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: admin
GF_USERS_ALLOW_SIGN_UP: "false"
...
2 changes: 2 additions & 0 deletions ansible/roles/node_exporter/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Ensure Node Exporter container is running
community.docker.docker_container:
name: node-exporter
Expand All @@ -10,3 +11,4 @@
command: ["--path.rootfs=/host"]
volumes:
- "/:/host:ro,rslave"
...
2 changes: 2 additions & 0 deletions ansible/roles/prometheus/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Ensure Prometheus directories exist
become: true
ansible.builtin.file:
Expand Down Expand Up @@ -36,3 +37,4 @@
read_only: true
tmpfs:
- /tmp
...
2 changes: 2 additions & 0 deletions ansible/roles/ssh_hardening/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
- name: Restart SSH
ansible.builtin.service:
name: ssh
state: restarted
...
8 changes: 5 additions & 3 deletions ansible/roles/ssh_hardening/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
- name: Disable SSH password authentication
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: "^#?PasswordAuthentication"
line: "PasswordAuthentication no"
state: present
backup: yes
backup: true
notify: Restart SSH

- name: Ensure ChallengeResponseAuthentication is disabled
Expand All @@ -29,7 +30,7 @@
regexp: "^#?AllowUsers"
line: "AllowUsers devops"
state: present
backup: yes
backup: true
notify: Restart SSH

- name: Disable SSH root login
Expand All @@ -38,5 +39,6 @@
regexp: "^#?PermitRootLogin"
line: "PermitRootLogin no"
state: present
backup: yes
backup: true
notify: Restart SSH
...
8 changes: 8 additions & 0 deletions infrastructure/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ resource "linode_firewall" "app_fw" {
ipv4 = ["192.168.0.0/16"]
}

inbound {
label = "allow-https"
action = "ACCEPT"
protocol = "TCP"
ports = "443"
ipv4 = ["0.0.0.0/0"]
}

inbound {
label = "allow-http"
action = "ACCEPT"
Expand Down