Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da2f0876dd | ||
|
|
cfb63da386 | ||
|
|
55193c7bd4 | ||
|
|
2aa5480d17 | ||
|
|
168c59f3ea | ||
|
|
58ffb82378 | ||
|
|
38241f82e3 | ||
|
|
9eac2c2057 | ||
|
|
feb6a2c962 | ||
|
|
619205e0a8 | ||
|
|
1361466dfe | ||
|
|
1fa863f107 | ||
|
|
605b4e8c7b | ||
|
|
e5b0a80bb2 | ||
|
|
c2b4181756 |
27
.github/workflows/ci-cd.yml
vendored
27
.github/workflows/ci-cd.yml
vendored
@@ -42,8 +42,13 @@ jobs:
|
||||
|
||||
- name: Validate Ansible syntax
|
||||
run: |
|
||||
mkdir -p test-inventory
|
||||
cat > test-inventory/hosts <<EOF
|
||||
[all]
|
||||
localhost ansible_connection=local
|
||||
EOF
|
||||
for playbook in playbooks/*.yml; do
|
||||
ansible-playbook --syntax-check "$playbook"
|
||||
ansible-playbook -i test-inventory/hosts --syntax-check "$playbook"
|
||||
done
|
||||
|
||||
test-ubuntu:
|
||||
@@ -52,8 +57,16 @@ jobs:
|
||||
needs: lint
|
||||
strategy:
|
||||
matrix:
|
||||
ubuntu_version: ['22.04', '24.04', '25.04']
|
||||
include:
|
||||
- ubuntu_version: '22.04'
|
||||
allow_failure: false
|
||||
- ubuntu_version: '24.04'
|
||||
allow_failure: false
|
||||
- ubuntu_version: '25.04'
|
||||
allow_failure: true
|
||||
|
||||
continue-on-error: ${{ matrix.allow_failure }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
@@ -81,7 +94,7 @@ jobs:
|
||||
echo "Testing syntax for all playbooks..."
|
||||
for playbook in playbooks/*.yml; do
|
||||
echo "Checking $playbook..."
|
||||
ansible-playbook "$playbook" --syntax-check
|
||||
ansible-playbook -i test-inventory/hosts "$playbook" --syntax-check
|
||||
done
|
||||
|
||||
- name: Test variable loading
|
||||
@@ -97,10 +110,10 @@ jobs:
|
||||
run: |
|
||||
echo "Testing basic container setup for Ubuntu ${{ matrix.ubuntu_version }}..."
|
||||
docker run --rm ubuntu:${{ matrix.ubuntu_version }} /bin/bash -c "
|
||||
export DEBIAN_FRONTEND=noninteractive &&
|
||||
apt-get update -o Acquire::Retries=5 -o Acquire::http::Timeout=30 || apt-get update -o Acquire::Retries=5 -o Acquire::http::Timeout=30 &&
|
||||
apt-get install -y --no-install-recommends python3 ca-certificates &&
|
||||
python3 --version &&
|
||||
set -e &&
|
||||
grep '^NAME=' /etc/os-release &&
|
||||
grep '^VERSION_ID=' /etc/os-release &&
|
||||
bash --version > /dev/null &&
|
||||
echo 'Ubuntu ${{ matrix.ubuntu_version }} container test successful'"
|
||||
|
||||
|
||||
|
||||
@@ -14,12 +14,15 @@ RUN mkdir -p /var/run/sshd /var/log/supervisor \
|
||||
&& echo 'ansible ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||
|
||||
# Install base system packages in a single layer
|
||||
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
|
||||
# Core system
|
||||
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
|
||||
# Core system
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
lsb-release \
|
||||
apt-transport-https \
|
||||
software-properties-common \
|
||||
# SSH and system control
|
||||
openssh-server \
|
||||
sudo \
|
||||
@@ -50,8 +53,8 @@ RUN apt-get update && apt-get install -y \
|
||||
# Web server
|
||||
nginx \
|
||||
# Database
|
||||
mysql-server \
|
||||
mysql-client \
|
||||
mariadb-server \
|
||||
mariadb-client \
|
||||
# PHP and extensions
|
||||
php8.4 \
|
||||
php8.4-fpm \
|
||||
@@ -84,7 +87,7 @@ RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/
|
||||
# Configure systemd
|
||||
RUN systemctl enable ssh \
|
||||
&& systemctl enable nginx \
|
||||
&& systemctl enable mysql \
|
||||
&& systemctl enable mysql mariadb \
|
||||
&& systemctl enable php8.4-fpm
|
||||
|
||||
# Create web directory structure
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/bash
|
||||
# Services für LEMP-Stack starten
|
||||
|
||||
# MySQL starten
|
||||
service mysql start
|
||||
# MySQL/MariaDB starten
|
||||
service mysql start || service mariadb start
|
||||
|
||||
# PHP-FPM starten
|
||||
service php8.4-fpm start
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
- name: Debug OS information
|
||||
debug:
|
||||
msg: |
|
||||
OS Family: {{ ansible_os_family }}
|
||||
Distribution: {{ ansible_distribution }}
|
||||
Version: {{ ansible_distribution_version }}
|
||||
OS Family: {{ ansible_facts["os_family"] }}
|
||||
Distribution: {{ ansible_facts["distribution"] }}
|
||||
Version: {{ ansible_facts["distribution_version"] }}
|
||||
Supported: Ubuntu/Debian family systems
|
||||
|
||||
- name: Verify supported OS
|
||||
fail:
|
||||
msg: "This playbook only supports Ubuntu/Debian systems. Detected: {{ ansible_os_family }}"
|
||||
when: ansible_os_family != "Debian"
|
||||
msg: "This playbook only supports Ubuntu/Debian systems. Detected {{ ansible_facts['os_family'] }}"
|
||||
when: ansible_facts["os_family"] != "Debian"
|
||||
|
||||
# Environment Detection and Configuration
|
||||
- name: Detect if running in Docker
|
||||
@@ -54,7 +54,7 @@
|
||||
vars:
|
||||
_auto_wp_url: >-
|
||||
{{ 'http://localhost:8080' if (deployment_environment == 'docker')
|
||||
else 'http://' + (ansible_default_ipv4.address | default('localhost')) }}
|
||||
else 'http://' + (ansible_facts["default_ipv4"]["address"] | default('localhost')) }}
|
||||
tags: always
|
||||
|
||||
- name: Debug deployment configuration
|
||||
@@ -66,9 +66,12 @@
|
||||
tags: always
|
||||
|
||||
vars:
|
||||
# Default PHP version (will be overridden by detection)
|
||||
php_version: "8.4"
|
||||
|
||||
# WordPress Configuration
|
||||
wordpress_path: "{{ web_root }}"
|
||||
wordpress_url: "http://{{ ansible_default_ipv4.address | default('localhost') }}"
|
||||
wordpress_url: "http://{{ ansible_facts['default_ipv4']['address'] | default('localhost') }}"
|
||||
|
||||
# Database Configuration (use inventory variables or these defaults)
|
||||
default_mysql_root_password: "{{ mysql_root_password | default('secure_root_password_123') }}"
|
||||
@@ -81,6 +84,30 @@
|
||||
# wp_admin_user, wp_admin_password, wp_admin_email, wp_site_title
|
||||
|
||||
tasks:
|
||||
# IMPORTANT: Pre-flight checks - create basic directory structure FIRST
|
||||
- name: Ensure /var/www exists
|
||||
file:
|
||||
path: /var/www
|
||||
state: directory
|
||||
mode: '0755'
|
||||
tags: [preflight]
|
||||
|
||||
- name: Create web root directory
|
||||
file:
|
||||
path: /var/www/html
|
||||
state: directory
|
||||
owner: www-data
|
||||
group: www-data
|
||||
mode: '0755'
|
||||
tags: [preflight]
|
||||
|
||||
- name: Create PHP-FPM log directory
|
||||
file:
|
||||
path: "/var/log/php{{ php_version }}-fpm"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
tags: [preflight]
|
||||
|
||||
# Package Installation
|
||||
- name: Update package cache
|
||||
apt:
|
||||
@@ -88,10 +115,65 @@
|
||||
cache_valid_time: 3600
|
||||
tags: packages
|
||||
|
||||
- name: Install all required packages
|
||||
package:
|
||||
name: "{{ packages }}"
|
||||
- name: Install essential packages
|
||||
apt:
|
||||
name:
|
||||
- gnupg
|
||||
- nginx
|
||||
state: present
|
||||
tags: [packages, nginx]
|
||||
|
||||
- name: Detect available PHP version and set fallback
|
||||
shell: |
|
||||
if apt-cache show php8.4-fpm >/dev/null 2>&1; then
|
||||
echo "8.4"
|
||||
elif apt-cache show php8.3-fpm >/dev/null 2>&1; then
|
||||
echo "8.3"
|
||||
else
|
||||
echo "none"
|
||||
fi
|
||||
register: php_version_detect
|
||||
changed_when: false
|
||||
tags: packages
|
||||
|
||||
- name: Set PHP version fact
|
||||
set_fact:
|
||||
php_version: "{{ php_version_detect.stdout }}"
|
||||
tags: packages
|
||||
|
||||
- name: Install PHP with fallback (try 8.4, fallback to 8.3)
|
||||
apt:
|
||||
name:
|
||||
- "php{{ php_version }}-fpm"
|
||||
- "php{{ php_version }}-mysql"
|
||||
- "php{{ php_version }}-curl"
|
||||
- "php{{ php_version }}-gd"
|
||||
- "php{{ php_version }}-intl"
|
||||
- "php{{ php_version }}-mbstring"
|
||||
- "php{{ php_version }}-soap"
|
||||
- "php{{ php_version }}-xml"
|
||||
- "php{{ php_version }}-xmlrpc"
|
||||
- "php{{ php_version }}-zip"
|
||||
- "php{{ php_version }}-opcache"
|
||||
- "php{{ php_version }}-redis"
|
||||
state: present
|
||||
register: php_install_result
|
||||
tags: packages
|
||||
|
||||
- name: Install remaining packages
|
||||
package:
|
||||
name: "{{ packages | reject('search', '^php') | list }}"
|
||||
state: present
|
||||
tags: packages
|
||||
|
||||
- name: Display PHP version installed
|
||||
debug:
|
||||
msg: "Using PHP version {{ php_version }}"
|
||||
tags: packages
|
||||
|
||||
- name: Set PHP FPM service name dynamically
|
||||
set_fact:
|
||||
php_fpm_service: "php{{ php_version }}-fpm"
|
||||
tags: packages
|
||||
|
||||
# Service Management
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
# Ubuntu/Debian LEMP WordPress installation
|
||||
- name: Install LEMP stack with WordPress (Ubuntu/Debian)
|
||||
- name: "Install LEMP stack with WordPress (Ubuntu/Debian)"
|
||||
hosts: all
|
||||
become: yes
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
- name: Debug OS information
|
||||
debug:
|
||||
msg: |
|
||||
OS Family: {{ ansible_os_family }}
|
||||
Distribution: {{ ansible_distribution }}
|
||||
Version: {{ ansible_distribution_version }}
|
||||
OS Family: {{ ansible_facts["os_family"] }}
|
||||
Distribution: {{ ansible_facts["distribution"] }}
|
||||
Version: {{ ansible_facts["distribution_version"] }}
|
||||
Supported: Ubuntu/Debian family systems
|
||||
|
||||
- name: Verify supported OS
|
||||
fail:
|
||||
msg: "This playbook only supports Ubuntu/Debian systems. Detected: {{ ansible_os_family }}"
|
||||
when: ansible_os_family != "Debian"
|
||||
msg: "This playbook only supports Ubuntu/Debian systems. Detected {{ ansible_facts['os_family'] }}"
|
||||
when: ansible_facts["os_family"] != "Debian"
|
||||
|
||||
# Environment Detection and Configuration
|
||||
- name: Detect if running in Docker
|
||||
@@ -54,7 +54,7 @@
|
||||
vars:
|
||||
_auto_wp_url: >-
|
||||
{{ 'http://localhost:8080' if (deployment_environment == 'docker')
|
||||
else 'http://' + (ansible_default_ipv4.address | default('localhost')) }}
|
||||
else 'http://' + (ansible_facts["default_ipv4"]["address"] | default('localhost')) }}
|
||||
tags: always
|
||||
|
||||
- name: Debug deployment configuration
|
||||
@@ -66,9 +66,12 @@
|
||||
tags: always
|
||||
|
||||
vars:
|
||||
# Default PHP version (will be overridden by detection)
|
||||
php_version: "8.4"
|
||||
|
||||
# WordPress Configuration
|
||||
wordpress_path: "{{ web_root }}"
|
||||
wordpress_url: "http://{{ ansible_default_ipv4.address | default('localhost') }}"
|
||||
wordpress_url: "http://{{ ansible_facts['default_ipv4']['address'] | default('localhost') }}"
|
||||
|
||||
# Database Configuration (use inventory variables or these defaults)
|
||||
default_mysql_root_password: "{{ mysql_root_password | default('secure_root_password_123') }}"
|
||||
@@ -84,6 +87,30 @@
|
||||
update_cron_enabled: true
|
||||
|
||||
tasks:
|
||||
# IMPORTANT: Pre-flight checks - create basic directory structure FIRST
|
||||
- name: Ensure /var/www exists
|
||||
file:
|
||||
path: /var/www
|
||||
state: directory
|
||||
mode: '0755'
|
||||
tags: [preflight]
|
||||
|
||||
- name: Create web root directory
|
||||
file:
|
||||
path: /var/www/html
|
||||
state: directory
|
||||
owner: www-data
|
||||
group: www-data
|
||||
mode: '0755'
|
||||
tags: [preflight]
|
||||
|
||||
- name: Create PHP-FPM log directory
|
||||
file:
|
||||
path: "/var/log/php{{ php_version }}-fpm"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
tags: [preflight]
|
||||
|
||||
# Package Installation
|
||||
- name: Update package cache
|
||||
apt:
|
||||
@@ -91,10 +118,63 @@
|
||||
cache_valid_time: 3600
|
||||
tags: packages
|
||||
|
||||
- name: Install all required packages
|
||||
package:
|
||||
name: "{{ packages }}"
|
||||
- name: Install essential packages
|
||||
apt:
|
||||
name:
|
||||
- gnupg
|
||||
- nginx
|
||||
state: present
|
||||
tags: [packages, nginx]
|
||||
|
||||
- name: Detect available PHP version and set fallback
|
||||
shell: |
|
||||
if apt-cache show php8.4-fpm >/dev/null 2>&1; then
|
||||
echo "8.4"
|
||||
elif apt-cache show php8.3-fpm >/dev/null 2>&1; then
|
||||
echo "8.3"
|
||||
else
|
||||
echo "none"
|
||||
fi
|
||||
register: php_version_detect
|
||||
changed_when: false
|
||||
tags: packages
|
||||
|
||||
- name: Set PHP version fact
|
||||
set_fact:
|
||||
php_version: "{{ php_version_detect.stdout }}"
|
||||
tags: packages
|
||||
|
||||
- name: Install PHP with fallback (try 8.4, fallback to 8.3)
|
||||
apt:
|
||||
name:
|
||||
- "php{{ php_version }}-fpm"
|
||||
- "php{{ php_version }}-mysql"
|
||||
- "php{{ php_version }}-curl"
|
||||
- "php{{ php_version }}-gd"
|
||||
- "php{{ php_version }}-intl"
|
||||
- "php{{ php_version }}-mbstring"
|
||||
- "php{{ php_version }}-soap"
|
||||
- "php{{ php_version }}-xml"
|
||||
- "php{{ php_version }}-xmlrpc"
|
||||
- "php{{ php_version }}-zip"
|
||||
state: present
|
||||
register: php_install_result
|
||||
tags: packages
|
||||
|
||||
- name: Install remaining packages
|
||||
package:
|
||||
name: "{{ packages | reject('search', '^php') | list }}"
|
||||
state: present
|
||||
tags: packages
|
||||
|
||||
- name: Display PHP version installed
|
||||
debug:
|
||||
msg: "Using PHP version {{ php_version }}"
|
||||
tags: packages
|
||||
|
||||
- name: Set PHP FPM service name dynamically
|
||||
set_fact:
|
||||
php_fpm_service: "php{{ php_version }}-fpm"
|
||||
tags: packages
|
||||
|
||||
# Service Management
|
||||
@@ -363,10 +443,8 @@
|
||||
- name: Configure WordPress auto-update settings
|
||||
command: >
|
||||
wp option update auto_update_core_minor enabled
|
||||
--path="{{ wordpress_path }}"
|
||||
--allow-root
|
||||
environment:
|
||||
HOME: "{{ wordpress_path }}"
|
||||
ignore_errors: yes
|
||||
tags: update
|
||||
|
||||
- name: Set up cron job for WordPress updates
|
||||
|
||||
@@ -49,14 +49,14 @@ define( 'WP_CACHE_KEY_SALT', '{{ domain_name | default('localhost') }}' );
|
||||
{% endif %}
|
||||
|
||||
// ** Authentifizierungs-Schlüssel und Salts ** //
|
||||
define( 'AUTH_KEY', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}' );
|
||||
define( 'SECURE_AUTH_KEY', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}2' );
|
||||
define( 'LOGGED_IN_KEY', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}3' );
|
||||
define( 'NONCE_KEY', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}4' );
|
||||
define( 'AUTH_SALT', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}5' );
|
||||
define( 'SECURE_AUTH_SALT', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}6' );
|
||||
define( 'LOGGED_IN_SALT', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}7' );
|
||||
define( 'NONCE_SALT', '{{ ansible_date_time.epoch }}put your unique phrase here{{ ansible_hostname }}8' );
|
||||
define( 'AUTH_KEY', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}' );
|
||||
define( 'SECURE_AUTH_KEY', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}2' );
|
||||
define( 'LOGGED_IN_KEY', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}3' );
|
||||
define( 'NONCE_KEY', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}4' );
|
||||
define( 'AUTH_SALT', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}5' );
|
||||
define( 'SECURE_AUTH_SALT', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}6' );
|
||||
define( 'LOGGED_IN_SALT', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}7' );
|
||||
define( 'NONCE_SALT', '{{ ansible_facts["date_time"]["epoch"] }}put your unique phrase here{{ ansible_facts["hostname"] }}8' );
|
||||
|
||||
// ** WordPress Tabellen-Präfix ** //
|
||||
$table_prefix = 'wp_';
|
||||
@@ -71,8 +71,8 @@ define( 'WP_DEBUG_DISPLAY', false );
|
||||
define( 'WP_HOME', 'https://{{ domain_name }}' );
|
||||
define( 'WP_SITEURL', 'https://{{ domain_name }}' );
|
||||
{% else %}
|
||||
define( 'WP_HOME', 'http://{{ domain_name }}{% if ansible_port is defined and ansible_port != 22 and ansible_port != 80 %}:{{ ansible_port }}{% endif %}' );
|
||||
define( 'WP_SITEURL', 'http://{{ domain_name }}{% if ansible_port is defined and ansible_port != 22 and ansible_port != 80 %}:{{ ansible_port }}{% endif %}' );
|
||||
define( 'WP_HOME', 'http://{{ domain_name }}{% if ansible_facts["port"] is defined and ansible_facts["port"] != 22 and ansible_facts["port"] != 80 %}:{{ ansible_facts["port"] }}{% endif %}' );
|
||||
define( 'WP_SITEURL', 'http://{{ domain_name }}{% if ansible_facts["port"] is defined and ansible_facts["port"] != 22 and ansible_facts["port"] != 80 %}:{{ ansible_facts["port"] }}{% endif %}' );
|
||||
{% endif %}
|
||||
|
||||
// ** Weitere Einstellungen ** //
|
||||
|
||||
@@ -1,36 +1,26 @@
|
||||
# Ubuntu/Debian family variables
|
||||
---
|
||||
# Package names for Ubuntu/Debian systems
|
||||
# Package names for Ubuntu/Debian systems (PHP version is detected and installed dynamically)
|
||||
packages:
|
||||
- nginx
|
||||
- mysql-server
|
||||
- php8.4-fpm
|
||||
- php8.4-mysql
|
||||
- php8.4-curl
|
||||
- php8.4-gd
|
||||
- php8.4-intl
|
||||
- php8.4-mbstring
|
||||
- php8.4-soap
|
||||
- php8.4-xml
|
||||
- php8.4-xmlrpc
|
||||
- php8.4-zip
|
||||
- mariadb-server
|
||||
- python3-pymysql
|
||||
- unzip
|
||||
- fail2ban
|
||||
- ufw
|
||||
|
||||
# Service names
|
||||
mysql_service: mysql
|
||||
mysql_service: mariadb
|
||||
nginx_service: nginx
|
||||
php_fpm_service: php8.4-fpm
|
||||
php_fpm_service: php{{ php_version }}-fpm
|
||||
|
||||
# Package manager
|
||||
package_manager: apt
|
||||
|
||||
# PHP paths
|
||||
php_fpm_config_path: /etc/php/8.4/fpm
|
||||
php_cli_config_path: /etc/php/8.4/cli
|
||||
php_fpm_pool_path: /etc/php/8.4/fpm/pool.d
|
||||
php_fpm_socket: /run/php/php8.4-fpm.sock
|
||||
# PHP paths (dynamic based on detected version)
|
||||
php_fpm_config_path: /etc/php/{{ php_version }}/fpm
|
||||
php_cli_config_path: /etc/php/{{ php_version }}/cli
|
||||
php_fpm_pool_path: /etc/php/{{ php_version }}/fpm/pool.d
|
||||
php_fpm_socket: /run/php/php{{ php_version }}-fpm.sock
|
||||
|
||||
# Nginx paths
|
||||
nginx_config_path: /etc/nginx
|
||||
|
||||
Reference in New Issue
Block a user