diff options
| author | Joe Carstairs <me@joeac.net> | 2026-08-11 21:44:26 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-08-11 21:44:26 +0100 |
| commit | 74b9185a404ace70030e57e0ad493478227a5eac (patch) | |
| tree | 5f32d05d842ef726412ead2932d9157fd2f1df58 | |
| parent | 4e73a59d76e8c4949908e766657f5d634d39fb67 (diff) | |
ansible installs joeac.net website
| -rw-r--r-- | ansible/playbook.yml | 6 | ||||
| -rw-r--r-- | ansible/roles/http/tasks/main.yml | 107 | ||||
| -rw-r--r-- | ansible/roles/http/templates/config.ini | 11 | ||||
| -rw-r--r-- | ansible/roles/http/templates/nginx/joeac.net.conf | 24 | ||||
| -rw-r--r-- | ansible/roles/http/templates/php-fpm/joeac.net.conf (renamed from http/php-fpm.conf) | 15 | ||||
| -rw-r--r-- | ansible/vars/common.yml | 2 | ||||
| -rw-r--r-- | ansible/vars/http.yml | 3 | ||||
| -rw-r--r-- | http/nginx.conf | 47 | ||||
| -rw-r--r-- | http/php/config.php | 24 |
9 files changed, 164 insertions, 75 deletions
diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 72330de..ee0b39d 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -11,15 +11,15 @@ - mox.yml - network.yml -- name: Install msmtp +- name: Install http hosts: "{{ services.http.host }}" become: true roles: - - msmtp + - http vars_files: - common.yml - email.yml - - msmtp.yml + - http.yml - name: Install ln hosts: "{{ services.ln.host }}" diff --git a/ansible/roles/http/tasks/main.yml b/ansible/roles/http/tasks/main.yml new file mode 100644 index 0000000..05fce26 --- /dev/null +++ b/ansible/roles/http/tasks/main.yml @@ -0,0 +1,107 @@ +- name: Install composer, make, nginx, PHP, PHP-FPM, and PHP-PDO (SQLITE) + community.general.apk: + name: + - composer + - make + - nginx + - php85-fpm + - php85-pdo + - php85-pdo_sqlite + +- name: Start nginx service and configure to restart on boot + ansible.builtin.service: + name: nginx + enabled: true + state: started + +- name: Start PHP-FPM service and configure to restart on boot + ansible.builtin.service: + name: php-fpm85 + enabled: true + state: started + +- name: Remove default PHP-FPM pool + register: default_phpfpm_pool + ansible.builtin.file: + path: /etc/php85/php-fpm.d/www.conf + state: absent + +- name: Install PHP-FPM pool for joeac.net website + register: joeacnet_phpfpm_pool + ansible.builtin.template: + src: php-fpm/joeac.net.conf + dest: /etc/php85/php-fpm.d/joeac.net.conf + owner: nginx + group: nginx + mode: "600" + +- name: Restart PHP-FPM service if config changed + when: default_phpfpm_pool is changed or joeacnet_phpfpm_pool is changed + ansible.builtin.service: + name: php-fpm85 + state: restarted + +- name: Remove default nginx site config + register: default_nginx_site_config + ansible.builtin.file: + path: /etc/nginx/http.d/default.conf + state: absent + +- name: Install joeac.net nginx site config + register: joeacnet_nginx_site_config + ansible.builtin.template: + src: nginx/joeac.net.conf + dest: /etc/nginx/http.d/joeac.net.conf + +- name: Restart nginx service if config changed + when: default_nginx_site_config is changed or joeacnet_nginx_site_config is changed + ansible.builtin.service: + name: nginx + state: restarted + +- name: Checkout joeac.net source code + ansible.builtin.git: + repo: https://git.joeac.net/joeac/joeac.net.git + dest: "{{ joeacnet_src_dir }}" + depth: 1 + version: main + +- name: Build joeac.net website + community.general.make: + chdir: "{{ joeacnet_src_dir }}/http" + +- name: Create joeac.net public directory + ansible.builtin.file: + path: "{{ http_files_dir }}" + state: directory + +- name: Configure website PHP + ansible.builtin.template: + src: config.ini + dest: "{{ http_files_dir }}/config.ini" + +- name: Symlink vendor to public directory + ansible.builtin.file: + src: "{{ joeacnet_src_dir }}/http/vendor" + dest: "{{ http_files_dir }}/vendor" + state: link + +- name: Symlink php to public directory + ansible.builtin.file: + src: "{{ joeacnet_src_dir }}/http/php" + dest: "{{ http_files_dir }}/php" + state: link + +- name: Symlink html to public directory + ansible.builtin.file: + src: "{{ joeacnet_src_dir }}/http/out" + dest: "{{ http_files_dir }}/html" + state: link + +- name: Touch database and grant rw permissions to nginx user + ansible.builtin.file: + path: "{{ http_files_dir }}/{{ http_database_filename }}" + state: touch + owner: nginx + group: nginx + mode: "600" diff --git a/ansible/roles/http/templates/config.ini b/ansible/roles/http/templates/config.ini new file mode 100644 index 0000000..4bbe7b1 --- /dev/null +++ b/ansible/roles/http/templates/config.ini @@ -0,0 +1,11 @@ +MAX_DAILY_EMAILS = 100 +CONTACT_MAILBOX = me@joeac.net +CONTACT_MAILBOX_NAME = Joe Carstairs +LOCAL_SMTP_FROM = jobot@mail.joeac.net +LOCAL_SMTP_FROM_NAME = Jobot +LOCAL_SMTP_HOST = mail.joeac.net +LOCAL_SMTP_PORT = 465 +LOCAL_SMTP_USER = jobot@mail.joeac.net +LOCAL_SMTP_PASSWORD = "{{ ( email_accounts | selectattr("name", "eq", "jobot") | first ).password | trim }}" +DB_SCHEME = sqlite +DB_PATH = {{ http_files_dir }}/{{ http_database_filename }} diff --git a/ansible/roles/http/templates/nginx/joeac.net.conf b/ansible/roles/http/templates/nginx/joeac.net.conf new file mode 100644 index 0000000..9f28fee --- /dev/null +++ b/ansible/roles/http/templates/nginx/joeac.net.conf @@ -0,0 +1,24 @@ +server { + listen {{ services.http.port }}; + listen [::]:{{ services.http.port }}; + server_name joeac.net; + + location / { + root {{ http_files_dir }}/html; + try_files $uri $uri.html $uri/index.html $uri.php $uri/index.php =404; + } + + error_page 404 /error.html; + + location ~ \.php$ { + root html; + fastcgi_pass unix:/run/php8.5-fpm-joeac.net-http.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME /var/joeac.net-http/html$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.sqlite { + deny all; + } +} diff --git a/http/php-fpm.conf b/ansible/roles/http/templates/php-fpm/joeac.net.conf index ca71d66..30c120d 100644 --- a/http/php-fpm.conf +++ b/ansible/roles/http/templates/php-fpm/joeac.net.conf @@ -1,7 +1,7 @@ [joeac.net] user = nginx group = nginx -listen = /run/php8.5-fpm-joeac.net-http.sock +listen = {{ http_phpfpm_socket }} listen.owner = nginx listen.group = nginx listen.mode = 0660 @@ -21,16 +21,3 @@ pm.start_servers = 4 pm.min_spare_servers = 2 pm.max_spare_servers = 8 pm.max_requests = 500 - -clear_env = no -env[MAX_DAILY_EMAILS] = $MAX_DAILY_EMAILS -env[CONTACT_MAILBOX] = $CONTACT_MAILBOX -env[CONTACT_MAILBOX_NAME] = $CONTACT_MAILBOX_NAME -env[LOCAL_SMTP_FROM] = $LOCAL_SMTP_FROM -env[LOCAL_SMTP_FROM_NAME] = $LOCAL_SMTP_FROM_NAME -env[LOCAL_SMTP_HOST] = $LOCAL_SMTP_HOST -env[LOCAL_SMTP_PORT] = $LOCAL_SMTP_PORT -env[LOCAL_SMTP_USER] = $LOCAL_SMTP_USER -env[LOCAL_SMTP_PASSWORD] = $LOCAL_SMTP_PASSWORD -env[DB_SCHEME] = $DB_SCHEME -env[DB_PATH] = $DB_PATH diff --git a/ansible/vars/common.yml b/ansible/vars/common.yml index 26767e3..b0d9030 100644 --- a/ansible/vars/common.yml +++ b/ansible/vars/common.yml @@ -1,3 +1,5 @@ +joeacnet_src_dir: /usr/share/src/joeac.net + services: actualbudget: port: 5006 diff --git a/ansible/vars/http.yml b/ansible/vars/http.yml new file mode 100644 index 0000000..6d19c74 --- /dev/null +++ b/ansible/vars/http.yml @@ -0,0 +1,3 @@ +http_files_dir: /var/joeac.net-http +http_database_filename: db.sqlite +http_phpfpm_socket: /run/php8.5-fpm-joeac.net-http.sock diff --git a/http/nginx.conf b/http/nginx.conf deleted file mode 100644 index ca4c2f4..0000000 --- a/http/nginx.conf +++ /dev/null @@ -1,47 +0,0 @@ -user nginx; -worker_processes auto; - -error_log /var/log/nginx/error.log notice; -pid /run/nginx.pid; - -events { - worker_connections 1024; -} - -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /var/log/nginx/access.log main; - sendfile on; - keepalive_timeout 65; - - server { - listen 80; - listen [::]:80; - server_name joeac.net; - - access_log /var/log/nginx/host.access.log main; - - location / { - root /usr/share/nginx/html; - try_files $uri $uri.html $uri/index.html $uri.php $uri/index.php =404; - } - - error_page 404 /error.html; - - location ~ \.php$ { - root html; - fastcgi_pass unix:/run/php8.5-fpm-joeac.net-http.sock; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; - include fastcgi_params; - } - - location ~ /\.sqlite { - deny all; - } - } -} diff --git a/http/php/config.php b/http/php/config.php index a83b493..cfe91d3 100644 --- a/http/php/config.php +++ b/http/php/config.php @@ -1,8 +1,10 @@ <?php namespace JoeacNet\Http\Config; +define("CONFIG", parse_ini_file(dirname(__FILE__, 2) . "/config.ini")); + function maxDailyEmails(): int|null { - $maxDailyEmails = getenv("MAX_DAILY_EMAILS"); + $maxDailyEmails = CONFIG["MAX_DAILY_EMAILS"]; if (!is_numeric($maxDailyEmails)) { return null; } @@ -11,50 +13,50 @@ function maxDailyEmails(): int|null function contactMailbox(): string|null { - return (string) getenv("CONTACT_MAILBOX"); + return (string) CONFIG["CONTACT_MAILBOX"]; } function contactMailboxName(): string|null { - return (string) getenv("CONTACT_MAILBOX_NAME"); + return (string) CONFIG["CONTACT_MAILBOX_NAME"]; } function localSmtpFrom(): string|null { - return (string) getenv("LOCAL_SMTP_FROM"); + return (string) CONFIG["LOCAL_SMTP_FROM"]; } function localSmtpFromName(): string|null { - return (string) getenv("LOCAL_SMTP_FROM_NAME"); + return (string) CONFIG["LOCAL_SMTP_FROM_NAME"]; } function localSmtpHost(): string|null { - return (string) getenv("LOCAL_SMTP_HOST"); + return (string) CONFIG["LOCAL_SMTP_HOST"]; } function localSmtpPort(): string|null { - return (string) getenv("LOCAL_SMTP_PORT"); + return (string) CONFIG["LOCAL_SMTP_PORT"]; } function localSmtpUser(): string|null { - return (string) getenv("LOCAL_SMTP_USER"); + return (string) CONFIG["LOCAL_SMTP_USER"]; } function localSmtpPass(): string|null { - return (string) getenv("LOCAL_SMTP_PASSWORD"); + return (string) CONFIG["LOCAL_SMTP_PASSWORD"]; } function dbScheme(): string|null { - return (string) getenv("DB_SCHEME"); + return (string) CONFIG["DB_SCHEME"]; } function dbPath(): string|null { - return (string) getenv("DB_PATH"); + return (string) CONFIG["DB_PATH"]; } |
