2022-01-01 19:24:52 +01:00
|
|
|
---
|
2022-04-14 21:41:04 +02:00
|
|
|
- name: "Install nginx via apt"
|
2023-08-30 23:13:59 +02:00
|
|
|
apt:
|
2022-01-01 19:24:52 +01:00
|
|
|
update_cache: yes
|
|
|
|
state: present
|
|
|
|
name:
|
2022-04-14 21:41:04 +02:00
|
|
|
- nginx
|
|
|
|
- python3-certbot
|
|
|
|
- python3-certbot-nginx
|
2022-01-01 19:24:52 +01:00
|
|
|
|
2022-04-14 22:07:02 +02:00
|
|
|
- name: Allow http port via ufw
|
|
|
|
community.general.ufw:
|
|
|
|
rule: allow
|
|
|
|
port: http
|
|
|
|
|
|
|
|
- name: Allow https port via ufw
|
|
|
|
community.general.ufw:
|
|
|
|
rule: allow
|
|
|
|
port: https
|
|
|
|
|
2022-04-14 22:55:36 +02:00
|
|
|
- name: Copy default nginx config
|
2023-08-30 23:13:59 +02:00
|
|
|
copy:
|
2022-04-14 22:55:36 +02:00
|
|
|
src: nginx.conf
|
|
|
|
dest: /etc/nginx/nginx.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
|
2022-04-14 21:41:04 +02:00
|
|
|
- name: Enable and restart nginx daemon
|
2023-08-30 23:13:59 +02:00
|
|
|
service:
|
2022-04-14 21:41:04 +02:00
|
|
|
name: nginx
|
2022-01-01 19:24:52 +01:00
|
|
|
state: restarted
|
|
|
|
enabled: yes
|
2022-02-05 20:00:55 +01:00
|
|
|
|
2022-04-14 23:28:13 +02:00
|
|
|
- name: Generate certificate for all proxied domains
|
2023-08-30 23:13:59 +02:00
|
|
|
command:
|
2022-04-14 23:34:50 +02:00
|
|
|
cmd: certbot certonly --non-interactive --agree-tos -m tormakristof@tormakristof.eu --nginx -d {{item.domain}}
|
2022-04-14 23:28:13 +02:00
|
|
|
with_items: "{{ proxy }}"
|
|
|
|
|
|
|
|
- name: Generate certificate for all static sites
|
2023-08-30 23:13:59 +02:00
|
|
|
command:
|
2022-04-14 23:34:50 +02:00
|
|
|
cmd: certbot certonly --non-interactive --agree-tos -m tormakristof@tormakristof.eu --nginx -d {{item.domain}}
|
2022-04-14 23:28:13 +02:00
|
|
|
with_items: "{{ static }}"
|
2022-04-14 21:41:04 +02:00
|
|
|
|
2022-05-04 19:20:27 +02:00
|
|
|
- name: Generate certificate for all redirect sites
|
2023-08-30 23:13:59 +02:00
|
|
|
command:
|
2022-04-17 14:24:18 +02:00
|
|
|
cmd: certbot certonly --non-interactive --agree-tos -m tormakristof@tormakristof.eu --nginx -d {{item.domain}}
|
|
|
|
with_items: "{{ redirect }}"
|
|
|
|
|
2022-04-14 21:41:04 +02:00
|
|
|
- name: "Generate certbot script"
|
2023-08-30 23:13:59 +02:00
|
|
|
template:
|
2022-04-14 21:41:04 +02:00
|
|
|
src: certbot.sh
|
2022-12-30 13:23:29 +01:00
|
|
|
dest: /etc/cron.weekly/certbot
|
2022-04-14 21:41:04 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0700'
|
|
|
|
|
|
|
|
- name: "Generate nginx configuration"
|
2023-08-30 23:13:59 +02:00
|
|
|
template:
|
2022-04-14 21:41:04 +02:00
|
|
|
src: nginx.conf
|
|
|
|
dest: /etc/nginx/nginx.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
|
2022-04-14 23:16:14 +02:00
|
|
|
- name: Validate nginx configuration
|
2023-08-30 23:13:59 +02:00
|
|
|
command:
|
2022-04-14 23:16:14 +02:00
|
|
|
cmd: nginx -t
|
|
|
|
|
|
|
|
- name: Reload nginx after configuration change
|
2023-08-30 23:13:59 +02:00
|
|
|
service:
|
2022-04-14 23:16:14 +02:00
|
|
|
name: nginx
|
|
|
|
state: reloaded
|
|
|
|
|
2022-04-14 23:43:03 +02:00
|
|
|
- name: "Remove any existing static file directories"
|
2023-08-30 23:13:59 +02:00
|
|
|
file:
|
2022-04-14 23:43:03 +02:00
|
|
|
path: "{{ item.directory }}"
|
|
|
|
state: absent
|
|
|
|
with_items: "{{ static }}"
|
|
|
|
|
2022-04-14 23:09:44 +02:00
|
|
|
- name: "Checkout static websites from git"
|
2023-08-30 23:13:59 +02:00
|
|
|
git:
|
2022-04-14 23:09:44 +02:00
|
|
|
repo: "{{ item.repo }}"
|
|
|
|
dest: "{{ item.directory }}"
|
|
|
|
with_items: "{{ static }}"
|
|
|
|
|
|
|
|
- name: "Remove .git directory from static websites"
|
2023-08-30 23:13:59 +02:00
|
|
|
file:
|
2022-04-14 23:43:03 +02:00
|
|
|
path: "{{ item.directory }}/.git"
|
2022-04-14 23:09:44 +02:00
|
|
|
state: absent
|
2022-04-14 23:28:13 +02:00
|
|
|
with_items: "{{ static }}"
|
2022-05-29 15:15:02 +02:00
|
|
|
|
|
|
|
- name: "Install nginx exporter"
|
2023-08-30 23:13:59 +02:00
|
|
|
apt:
|
2022-05-29 15:15:02 +02:00
|
|
|
update_cache: yes
|
|
|
|
state: present
|
|
|
|
name:
|
|
|
|
- prometheus-nginx-exporter
|
|
|
|
|
2023-03-05 18:53:55 +01:00
|
|
|
- name: Copy nginx exporter config
|
2023-08-30 23:13:59 +02:00
|
|
|
copy:
|
2023-03-05 18:26:08 +01:00
|
|
|
src: prometheus-nginx-exporter
|
|
|
|
dest: /etc/default/prometheus-nginx-exporter
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
|
2022-05-29 15:24:02 +02:00
|
|
|
- name: Enable and restart exporter daemon
|
2023-08-30 23:13:59 +02:00
|
|
|
service:
|
2022-05-29 15:24:02 +02:00
|
|
|
name: prometheus-nginx-exporter
|
|
|
|
state: restarted
|
|
|
|
enabled: yes
|
|
|
|
|
2022-05-29 15:15:02 +02:00
|
|
|
- name: Allow nginx exporter via ufw
|
|
|
|
community.general.ufw:
|
|
|
|
rule: allow
|
|
|
|
port: 9113
|
|
|
|
proto: tcp
|
|
|
|
src: 192.168.69.0/24
|
2022-04-16 19:55:29 +02:00
|
|
|
...
|