2022-01-01 19:24:52 +01:00
|
|
|
---
|
2023-03-05 18:53:55 +01:00
|
|
|
- name: Allow https port via ufw
|
|
|
|
community.general.ufw:
|
|
|
|
rule: allow
|
|
|
|
port: https
|
2023-08-28 09:49:07 +02:00
|
|
|
src: {{ item }}
|
|
|
|
with_items: "{{ webgw_allowedranges }}"
|
2023-03-05 18:53:55 +01:00
|
|
|
|
2022-04-14 23:52:27 +02:00
|
|
|
- name: "Install Nginx via apt"
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.apt:
|
2022-04-14 23:52:27 +02:00
|
|
|
update_cache: yes
|
|
|
|
state: present
|
|
|
|
name:
|
|
|
|
- nginx
|
2023-03-05 18:37:38 +01:00
|
|
|
- python3-certbot
|
2023-03-05 19:48:09 +01:00
|
|
|
- python3-certbot-dns-cloudflare
|
2022-04-14 23:52:27 +02:00
|
|
|
|
2022-04-16 20:01:29 +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-16 14:21:53 +02:00
|
|
|
- name: Enable and restart nginx daemon
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.service:
|
2022-04-16 14:21:53 +02:00
|
|
|
name: nginx
|
|
|
|
state: restarted
|
|
|
|
enabled: yes
|
|
|
|
|
2023-03-05 19:48:09 +01:00
|
|
|
- name: "Get Cloudflare token from local environment variable"
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
cloudflare_token: "{{ lookup('env', 'CLOUDFLARE_TOKEN') }}"
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: "Render Cloudflare Certbot plugin configuration"
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: cf-creds.ini
|
|
|
|
dest: /root/cf-creds.ini
|
2023-03-05 19:52:33 +01:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0600
|
2023-03-05 19:48:09 +01:00
|
|
|
|
2023-03-05 18:26:08 +01:00
|
|
|
- name: Generate certificate for all server instances
|
2023-07-25 17:17:15 +02:00
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: certbot certonly --non-interactive --agree-tos -m iam@tormakristof.eu --dns-cloudflare --dns-cloudflare-credentials /root/cf-creds.ini -d {{item.domain}}
|
2023-03-05 18:26:08 +01:00
|
|
|
with_items: "{{ webserver }}"
|
|
|
|
|
|
|
|
- name: "Generate certbot script"
|
|
|
|
ansible.builtin.template:
|
2023-03-05 20:03:50 +01:00
|
|
|
src: certbot.sh
|
2023-03-05 18:26:08 +01:00
|
|
|
dest: /etc/cron.weekly/certbot
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0700'
|
|
|
|
|
2022-04-16 18:04:52 +02:00
|
|
|
- name: "Generate nginx configuration"
|
|
|
|
ansible.builtin.template:
|
2022-04-14 23:52:27 +02:00
|
|
|
src: nginx.conf
|
|
|
|
dest: /etc/nginx/nginx.conf
|
2022-01-01 19:24:52 +01:00
|
|
|
owner: root
|
2022-04-14 23:52:27 +02:00
|
|
|
group: root
|
2022-04-16 18:04:52 +02:00
|
|
|
mode: '0644'
|
2022-01-01 19:24:52 +01:00
|
|
|
|
2022-04-16 14:21:53 +02:00
|
|
|
- name: Reload nginx daemon
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.service:
|
2022-04-14 23:52:27 +02:00
|
|
|
name: nginx
|
2022-04-16 14:21:53 +02:00
|
|
|
state: reloaded
|
2022-02-05 20:00:55 +01:00
|
|
|
|
2022-05-29 15:15:02 +02:00
|
|
|
- name: "Install nginx exporter"
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.apt:
|
2022-05-29 15:15:02 +02:00
|
|
|
update_cache: yes
|
|
|
|
state: present
|
|
|
|
name:
|
|
|
|
- prometheus-nginx-exporter
|
|
|
|
|
|
|
|
- name: Allow nginx exporter via ufw
|
|
|
|
community.general.ufw:
|
|
|
|
rule: allow
|
|
|
|
port: 9113
|
|
|
|
proto: tcp
|
|
|
|
src: 192.168.69.0/24
|
|
|
|
|
2023-03-05 18:53:55 +01:00
|
|
|
- name: Copy nginx exporter config
|
2022-05-29 17:25:58 +02:00
|
|
|
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
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.service:
|
2022-05-29 15:24:02 +02:00
|
|
|
name: prometheus-nginx-exporter
|
|
|
|
state: restarted
|
|
|
|
enabled: yes
|
2022-04-16 19:55:29 +02:00
|
|
|
...
|