2022-01-01 19:24:52 +01:00
|
|
|
---
|
2022-04-14 21:41:04 +02:00
|
|
|
- name: "Install nginx via apt"
|
2022-01-01 19:24:52 +01:00
|
|
|
apt:
|
|
|
|
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
|
|
|
|
ansible.builtin.copy:
|
|
|
|
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
|
2022-01-01 19:24:52 +01: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
|
|
|
|
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
|
|
|
|
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
|
2022-04-17 14:24:18 +02:00
|
|
|
command:
|
|
|
|
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"
|
|
|
|
ansible.builtin.template:
|
|
|
|
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"
|
|
|
|
ansible.builtin.template:
|
|
|
|
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
|
|
|
|
command:
|
|
|
|
cmd: nginx -t
|
|
|
|
|
|
|
|
- name: Reload nginx after configuration change
|
|
|
|
service:
|
|
|
|
name: nginx
|
|
|
|
state: reloaded
|
|
|
|
|
2022-04-14 23:43:03 +02:00
|
|
|
- name: "Remove any existing static file directories"
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ item.directory }}"
|
|
|
|
state: absent
|
|
|
|
with_items: "{{ static }}"
|
|
|
|
|
2022-04-14 23:09:44 +02:00
|
|
|
- name: "Checkout static websites from git"
|
|
|
|
ansible.builtin.git:
|
|
|
|
repo: "{{ item.repo }}"
|
|
|
|
dest: "{{ item.directory }}"
|
|
|
|
with_items: "{{ static }}"
|
|
|
|
|
|
|
|
- name: "Remove .git directory from static websites"
|
|
|
|
ansible.builtin.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"
|
|
|
|
apt:
|
|
|
|
update_cache: yes
|
|
|
|
state: present
|
|
|
|
name:
|
|
|
|
- prometheus-nginx-exporter
|
|
|
|
|
2023-03-05 18:26:08 +01:00
|
|
|
- name: Copy default nginx config
|
|
|
|
ansible.builtin.copy:
|
|
|
|
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
|
|
|
|
service:
|
|
|
|
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
|
|
|
...
|