mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-21 20:31:02 +01:00
Compare commits
4 Commits
e2ee58e6a5
...
2e3e54f11f
Author | SHA1 | Date | |
---|---|---|---|
2e3e54f11f | |||
0b895e5694 | |||
5daf712a95 | |||
d1150ed038 |
@ -4,10 +4,11 @@
|
||||
|
||||
randomized_delay_sec: "15min"
|
||||
|
||||
on_calendar_btrfs_health_check: "*-*-* 00:00:00"
|
||||
on_calendar_btrfs_health_check: "*-*-* 00:00:00"
|
||||
on_calendar_journalctl_health_check: "*-*-* 00:00:00"
|
||||
on_calendar_disc_space_check: "*-*-* 06,12,18,00:00:00"
|
||||
on_calendar_docker_health_check: "*-*-* 09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00,01,02:00:00"
|
||||
on_calendar_nginx_health_check: "*-*-* 09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00,01,02:15:00"
|
||||
|
||||
on_calendar_backups_cleanup: "*-*-* 06,12,18,00:30:00"
|
||||
on_calendar_free_disc_space: "*-*-* 07,13,19,01:30:00"
|
||||
|
@ -11,6 +11,8 @@ PEERTUBE_DB_HOSTNAME=database
|
||||
PEERTUBE_WEBSERVER_HOSTNAME={{domain}}
|
||||
PEERTUBE_TRUST_PROXY=["127.0.0.1", "loopback"]
|
||||
|
||||
PEERTUBE_SECRET={{peertube_secret}}
|
||||
|
||||
# E-mail configuration
|
||||
PEERTUBE_SMTP_USERNAME={{system_email_username}}
|
||||
PEERTUBE_SMTP_PASSWORD={{system_email_password}}
|
||||
|
7
roles/health-nginx/README.md
Normal file
7
roles/health-nginx/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# health-nginx
|
||||
|
||||
Sends a health report for nginx configurations. This role was created with the help of ChatGPT. The conversation you will find [here](https://chat.openai.com/share/4033be29-12a6-40a3-bf3c-fc5d57dba8cb).
|
||||
|
||||
## see
|
||||
- https://nginx.org/en/docs/
|
||||
- https://docs.ansible.com/ansible/latest/modules/uri_module.html
|
53
roles/health-nginx/files/health-nginx.py
Normal file
53
roles/health-nginx/files/health-nginx.py
Normal file
@ -0,0 +1,53 @@
|
||||
import os
|
||||
import requests
|
||||
import sys
|
||||
import re
|
||||
|
||||
# Define the path to the nginx configuration directory
|
||||
config_path = '/etc/nginx/conf.d/'
|
||||
|
||||
# Initialize the error counter
|
||||
error_counter = 0
|
||||
|
||||
# Regex pattern to match domain.tld or subdomain.domain.tld
|
||||
pattern = re.compile(r"^(?:[\w-]+\.)?[\w-]+\.[\w-]+\.conf$")
|
||||
|
||||
# Iterate over each file in the configuration directory
|
||||
for filename in os.listdir(config_path):
|
||||
if filename.endswith('.conf') and pattern.match(filename):
|
||||
# Extract the domain and subdomain from the filename
|
||||
name = filename.replace('.conf', '')
|
||||
parts = name.split('.')
|
||||
|
||||
# Prepare the URL and expected status codes
|
||||
url = f"http://{name}"
|
||||
|
||||
# Determine expected status codes based on subdomain
|
||||
if len(parts) == 3 and parts[0] == 'www':
|
||||
expected_statuses = [200,301]
|
||||
elif len(parts) == 3 and parts[0] == 's':
|
||||
expected_statuses = [403]
|
||||
elif len(parts) <= 3:
|
||||
# For domain.tld where no specific subdomain is present
|
||||
expected_statuses = [200, 301]
|
||||
else:
|
||||
# Skip files that don't match the schema
|
||||
continue
|
||||
|
||||
try:
|
||||
# Send a HEAD request to get only the response header
|
||||
response = requests.head(url, allow_redirects=True)
|
||||
|
||||
# Check if the status code matches the expected statuses
|
||||
if response.status_code in expected_statuses:
|
||||
print(f"{name}: ok")
|
||||
else:
|
||||
print(f"{name}: error")
|
||||
error_counter += 1
|
||||
except requests.RequestException as e:
|
||||
# Handle exceptions for requests like connection errors
|
||||
print(f"{name}: error due to {e}")
|
||||
error_counter += 1
|
||||
|
||||
# Exit the script with the number of errors as the exit code
|
||||
sys.exit(error_counter)
|
12
roles/health-nginx/handlers/main.yml
Normal file
12
roles/health-nginx/handlers/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: "reload health-nginx.service"
|
||||
systemd:
|
||||
name: health-nginx.service
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: "restart health-nginx.timer"
|
||||
systemd:
|
||||
name: health-nginx.timer
|
||||
state: restarted
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
3
roles/health-nginx/meta/main.yml
Normal file
3
roles/health-nginx/meta/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
dependencies:
|
||||
- python-pip
|
||||
- systemd_notifier
|
29
roles/health-nginx/tasks/main.yml
Normal file
29
roles/health-nginx/tasks/main.yml
Normal file
@ -0,0 +1,29 @@
|
||||
- name: Install required Python modules
|
||||
pacman:
|
||||
name: python-requests
|
||||
state: present
|
||||
|
||||
- name: "create {{ nginx_health_check_folder }}"
|
||||
file:
|
||||
path: "{{ nginx_health_check_folder }}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: create health-nginx.py
|
||||
copy:
|
||||
src: health-nginx.py
|
||||
dest: "{{ nginx_health_check_folder }}health-nginx.py"
|
||||
|
||||
- name: create health-nginx.service
|
||||
template:
|
||||
src: health-nginx.service.j2
|
||||
dest: /etc/systemd/system/health-nginx.service
|
||||
notify: reload health-nginx.service
|
||||
|
||||
- name: create health-nginx.timer
|
||||
template:
|
||||
src: health-nginx.timer.j2
|
||||
dest: "/etc/systemd/system/health-nginx.timer"
|
||||
register: health_nginx_timer
|
||||
changed_when: health_nginx_timer.changed or activate_all_timers | default(false) | bool
|
||||
notify: restart health-nginx.timer
|
7
roles/health-nginx/templates/health-nginx.service.j2
Normal file
7
roles/health-nginx/templates/health-nginx.service.j2
Normal file
@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Check nginx configuration status
|
||||
OnFailure=systemd-notifier@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/python3 {{ nginx_health_check_folder }}health-nginx.py
|
10
roles/health-nginx/templates/health-nginx.timer.j2
Normal file
10
roles/health-nginx/templates/health-nginx.timer.j2
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=starts health-nginx.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{ on_calendar_nginx_health_check }}
|
||||
RandomizedDelaySec={{ randomized_delay_sec }}
|
||||
Persistent=false
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
1
roles/health-nginx/vars/main.yml
Normal file
1
roles/health-nginx/vars/main.yml
Normal file
@ -0,0 +1 @@
|
||||
nginx_health_check_folder: "{{ path_administrator_scripts }}health-nginx/"
|
2
roles/nginx/meta/main.yml
Normal file
2
roles/nginx/meta/main.yml
Normal file
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- health-nginx
|
Loading…
Reference in New Issue
Block a user