feat: v2.0.0 production-ready release with Redis, OPcache and Nginx optimizations

This commit is contained in:
Sebastian Palencsár
2025-06-21 00:08:09 +02:00
parent d3009617e4
commit e199772e92
55 changed files with 3408 additions and 3886 deletions

View File

@@ -30,22 +30,52 @@
msg: "This playbook only supports Ubuntu/Debian systems. Detected: {{ ansible_os_family }}"
when: ansible_os_family != "Debian"
# Environment Detection and Configuration
- name: Detect if running in Docker
stat:
path: /.dockerenv
register: docker_env
tags: always
- name: Check for deployment_environment override
set_fact:
environment_override: "{{ deployment_environment is defined }}"
tags: always
- name: Set deployment environment (auto-detect or override)
set_fact:
deployment_environment: "{{ deployment_environment | default('docker' if docker_env.stat.exists else 'bare_metal') }}"
tags: always
- name: Set WordPress site URL with smart defaults
set_fact:
wp_site_url: "{{ wp_site_url | default(_auto_wp_url) }}"
vars:
_auto_wp_url: "{{ 'http://localhost:8080' if (deployment_environment == 'docker') else 'http://' + (ansible_default_ipv4.address | default('localhost')) }}"
tags: always
- name: Debug deployment configuration
debug:
msg: |
Environment: {{ deployment_environment }} ({{ 'overridden' if environment_override else 'auto-detected' }})
WordPress URL: {{ wp_site_url }}
Docker detected: {{ docker_env.stat.exists }}
tags: always
vars:
# WordPress Configuration
wordpress_path: "{{ web_root }}"
wordpress_url: "http://{{ ansible_default_ipv4.address | default('localhost') }}"
# Database Configuration
mysql_root_password: "{{ mysql_root_password | default('secure_root_password_' + ansible_date_time.epoch) }}"
wordpress_db_name: "{{ wordpress_db_name | default('wordpress_db') }}"
wordpress_db_user: "{{ wordpress_db_user | default('wordpress_user') }}"
wordpress_db_password: "{{ wordpress_db_password | default('secure_wp_password_' + ansible_date_time.epoch) }}"
# Database Configuration (use inventory variables or these defaults)
default_mysql_root_password: "{{ mysql_root_password | default('secure_root_password_123') }}"
default_wordpress_db_name: "{{ wordpress_db_name | default('wordpress_db') }}"
default_wordpress_db_user: "{{ wordpress_db_user | default('wordpress_user') }}"
default_wordpress_db_password: "{{ wordpress_db_password | default('secure_wp_password_123') }}"
# WordPress Admin
wp_admin_user: "{{ wp_admin_user | default('admin') }}"
wp_admin_password: "{{ wp_admin_password | default('secure_admin_password_' + ansible_date_time.epoch) }}"
wp_admin_email: "{{ wp_admin_email | default('admin@localhost') }}"
wp_site_title: "{{ wp_site_title | default('My WordPress Site') }}"
# WordPress Admin (use inventory variables directly)
# These variables come from inventory/production.yml
# wp_admin_user, wp_admin_password, wp_admin_email, wp_site_title
tasks:
# Package Installation
@@ -95,13 +125,15 @@
- "443"
tags: firewall
# MySQL Security
- name: Set MySQL root password
# MySQL Security (Ubuntu 24.04 fix for auth_socket)
- name: Set MySQL root password (using auth_socket first)
mysql_user:
name: root
password: "{{ mysql_root_password }}"
plugin: mysql_native_password
login_unix_socket: /var/run/mysqld/mysqld.sock
state: present
become: true
tags: mysql
- name: Create MySQL configuration for root
@@ -150,6 +182,12 @@
mode: '0755'
tags: wordpress
- name: Remove default nginx index file
file:
path: "{{ wordpress_path }}/index.nginx-debian.html"
state: absent
tags: wordpress
- name: Download WordPress
get_url:
url: https://wordpress.org/latest.tar.gz
@@ -165,7 +203,7 @@
tags: wordpress
- name: Copy WordPress files
command: "cp -r /tmp/wordpress/* {{ wordpress_path }}/"
command: "cp -r /tmp/wordpress/. {{ wordpress_path }}/"
args:
creates: "{{ wordpress_path }}/wp-config-sample.php"
tags: wordpress
@@ -178,10 +216,22 @@
recurse: yes
tags: wordpress
# SSL Configuration (optional)
- name: Generate self-signed SSL certificate (if SSL enabled but no cert provided)
command: >
openssl req -x509 -nodes -days 365 -newkey rsa:2048
-keyout {{ ssl_cert_key_path | default('/etc/ssl/private/nginx-selfsigned.key') }}
-out {{ ssl_cert_path | default('/etc/ssl/certs/nginx-selfsigned.crt') }}
-subj "/C=DE/ST=State/L=City/O=Organization/OU=OrgUnit/CN={{ domain_name }}"
when:
- ssl_enabled | default(false)
- not (ssl_cert_path is defined and ssl_cert_key_path is defined)
tags: ssl
# Nginx Configuration
- name: Configure Nginx for WordPress
template:
src: ../templates/wordpress.nginx.j2
src: ../templates/{% if ssl_enabled | default(false) %}wordpress-ssl.nginx.j2{% else %}wordpress.nginx.j2{% endif %}
dest: "{{ nginx_sites_available }}/wordpress"
notify: restart nginx
tags: nginx
@@ -244,7 +294,6 @@
- name: Verify WP-CLI installation
command: wp --info
become_user: www-data
environment:
HOME: "{{ wordpress_path }}"
register: wp_cli_info
@@ -255,6 +304,39 @@
var: wp_cli_info.stdout_lines
tags: wp-cli
# WordPress Core Installation
- name: Install WordPress Core
command: >
wp core install
--url="{{ wp_site_url }}"
--title="{{ wp_site_title }}"
--admin_user="{{ wp_admin_user }}"
--admin_password="{{ wp_admin_password }}"
--admin_email="{{ wp_admin_email }}"
--path="{{ wordpress_path }}"
--allow-root
environment:
HOME: "{{ wordpress_path }}"
tags: wp-install
- name: Set WordPress file ownership after installation
file:
path: "{{ wordpress_path }}"
owner: "{{ nginx_user }}"
group: "{{ nginx_user }}"
recurse: yes
tags: wp-install
- name: Display WordPress installation success
debug:
msg: |
WordPress installation completed!
URL: {{ wp_site_url }}
Admin User: {{ wp_admin_user }}
Admin Password: {{ wp_admin_password }}
Admin Email: {{ wp_admin_email }}
tags: wp-install
handlers:
- name: restart nginx
service: