summaryrefslogtreecommitdiff
path: root/roles/http
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-08-13 16:35:47 +0100
committerJoe Carstairs <me@joeac.net>2026-08-13 16:35:47 +0100
commit9f2ebc2cce3af0e685677c23f2098c115e034adf (patch)
treebc6609cf851ee3f0a4f572d762b4ea35a34610f6 /roles/http
parentf31e65c51681823ade14abad87c742101a1b823d (diff)
move ansible/ dir to root
Diffstat (limited to 'roles/http')
-rw-r--r--roles/http/tasks/main.yml115
-rw-r--r--roles/http/templates/config.ini11
-rw-r--r--roles/http/templates/nginx/joeac.net.conf24
-rw-r--r--roles/http/templates/php-fpm/joeac.net.conf23
4 files changed, 173 insertions, 0 deletions
diff --git a/roles/http/tasks/main.yml b/roles/http/tasks/main.yml
new file mode 100644
index 0000000..7676633
--- /dev/null
+++ b/roles/http/tasks/main.yml
@@ -0,0 +1,115 @@
+- 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: "{{ src_dir }}/joeac.net"
+ depth: 1
+ version: main
+
+- name: Build joeac.net website
+ community.general.make:
+ chdir: "{{ src_dir }}/joeac.net/http"
+
+- name: Create joeac.net public directory
+ ansible.builtin.file:
+ path: "{{ http_files_dir }}"
+ state: directory
+ owner: nginx
+ group: nginx
+
+- name: Configure website PHP with config.ini
+ ansible.builtin.template:
+ src: config.ini
+ dest: "{{ src_dir }}/joeac.net/http/config.ini"
+
+- name: Symlink config.ini
+ ansible.builtin.file:
+ src: "{{ src_dir }}/joeac.net/http/config.ini"
+ dest: "{{ http_files_dir }}/config.ini"
+ state: link
+
+- name: Symlink vendor to public directory
+ ansible.builtin.file:
+ src: "{{ src_dir }}/joeac.net/http/vendor"
+ dest: "{{ http_files_dir }}/vendor"
+ state: link
+
+- name: Symlink php to public directory
+ ansible.builtin.file:
+ src: "{{ src_dir }}/joeac.net/http/php"
+ dest: "{{ http_files_dir }}/php"
+ state: link
+
+- name: Symlink html to public directory
+ ansible.builtin.file:
+ src: "{{ src_dir }}/joeac.net/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/roles/http/templates/config.ini b/roles/http/templates/config.ini
new file mode 100644
index 0000000..4bbe7b1
--- /dev/null
+++ b/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/roles/http/templates/nginx/joeac.net.conf b/roles/http/templates/nginx/joeac.net.conf
new file mode 100644
index 0000000..9f28fee
--- /dev/null
+++ b/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/roles/http/templates/php-fpm/joeac.net.conf b/roles/http/templates/php-fpm/joeac.net.conf
new file mode 100644
index 0000000..30c120d
--- /dev/null
+++ b/roles/http/templates/php-fpm/joeac.net.conf
@@ -0,0 +1,23 @@
+[joeac.net]
+user = nginx
+group = nginx
+listen = {{ http_phpfpm_socket }}
+listen.owner = nginx
+listen.group = nginx
+listen.mode = 0660
+
+access.log = /var/log/php85/$pool.access.log
+access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{milli}d %{kilo}M %C%%"
+catch_workers_output = yes
+php_admin_value[error_log] = /var/log/php85/$pool.error.log
+php_admin_flag[log_errors] = on
+
+php_admin_value[disable_functions] = exec,passthru,shell_exec,system
+php_admin_flag[allow_url_fopen] = off
+
+pm = dynamic
+pm.max_children = 20
+pm.start_servers = 4
+pm.min_spare_servers = 2
+pm.max_spare_servers = 8
+pm.max_requests = 500