164 lines
5.1 KiB
YAML
164 lines
5.1 KiB
YAML
- name: Install LAMP stack with phpMyAdmin (Debian + RHEL)
|
|
hosts: lampservers
|
|
become: yes
|
|
vars:
|
|
mysql_root_password: "ts;hffkX^8Mtip'8!O,!"
|
|
phpmyadmin_password: "ts;hffkX^8Mtip'8!O,!"
|
|
php_version: "default" # You can override this per-host/group
|
|
|
|
# Debian/Ubuntu package lists
|
|
deb_packages:
|
|
- apache2
|
|
- mysql-server
|
|
- php
|
|
- php-mysql
|
|
- libapache2-mod-php
|
|
- php-cli
|
|
- php-cgi
|
|
- php-gd
|
|
- php-json
|
|
- php-mbstring
|
|
- php-zip
|
|
- phpmyadmin
|
|
|
|
# RHEL/CentOS/Alma/Rocky package lists
|
|
rhel_packages:
|
|
- httpd
|
|
- mariadb-server
|
|
- php
|
|
- php-mysqlnd
|
|
- php-gd
|
|
- php-json
|
|
- php-mbstring
|
|
- php-zip
|
|
- epel-release
|
|
|
|
tasks:
|
|
|
|
- name: Install required packages (Debian/Ubuntu)
|
|
apt:
|
|
name: "{{ deb_packages }}"
|
|
state: present
|
|
update_cache: yes
|
|
when: ansible_facts['os_family'] == "Debian"
|
|
|
|
- name: Preseed MySQL and phpMyAdmin passwords (Debian/Ubuntu)
|
|
debconf:
|
|
name: "{{ item.name }}"
|
|
question: "{{ item.question }}"
|
|
value: "{{ item.value }}"
|
|
vtype: "string"
|
|
loop:
|
|
- { name: "mysql-server", question: "mysql-server/root_password", value: "{{ mysql_root_password }}" }
|
|
- { name: "mysql-server", question: "mysql-server/root_password_again", value: "{{ mysql_root_password }}" }
|
|
- { name: "phpmyadmin", question: "phpmyadmin/phpmyadmin/reconfigure-webserver", value: "apache2" }
|
|
- { name: "phpmyadmin", question: "phpmyadmin/phpmyadmin/dbconfig-install", value: "true" }
|
|
- { name: "phpmyadmin", question: "phpmyadmin/app-password-confirm", value: "{{ phpmyadmin_password }}" }
|
|
- { name: "phpmyadmin", question: "phpmyadmin/mysql/admin-pass", value: "{{ mysql_root_password }}" }
|
|
- { name: "phpmyadmin", question: "phpmyadmin/mysql/app-pass", value: "{{ phpmyadmin_password }}" }
|
|
when: ansible_facts['os_family'] == "Debian"
|
|
|
|
- name: Ensure Apache is installed and enabled (Debian)
|
|
service:
|
|
name: apache2
|
|
state: started
|
|
enabled: yes
|
|
when: ansible_facts['os_family'] == "Debian"
|
|
|
|
- name: Ensure MySQL is installed and enabled (Debian)
|
|
service:
|
|
name: mysql
|
|
state: started
|
|
enabled: yes
|
|
when: ansible_facts['os_family'] == "Debian"
|
|
|
|
- name: Install EPEL repo for phpMyAdmin (RHEL/CentOS)
|
|
yum:
|
|
name: epel-release
|
|
state: present
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Install required packages (RHEL/CentOS)
|
|
yum:
|
|
name: "{{ rhel_packages }}"
|
|
state: present
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Install phpMyAdmin (RHEL/CentOS)
|
|
yum:
|
|
name: phpMyAdmin
|
|
state: present
|
|
ignore_errors: yes
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Ensure Apache is installed and enabled (RHEL)
|
|
service:
|
|
name: httpd
|
|
state: started
|
|
enabled: yes
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Ensure MariaDB is installed and enabled (RHEL)
|
|
service:
|
|
name: mariadb
|
|
state: started
|
|
enabled: yes
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Enable Apache mod_rewrite (Debian)
|
|
community.general.apache2_module:
|
|
name: rewrite
|
|
state: present
|
|
when: ansible_facts['os_family'] == "Debian"
|
|
|
|
- name: Enable mod_rewrite (RHEL/CentOS)
|
|
lineinfile:
|
|
dest: /etc/httpd/conf/httpd.conf
|
|
regexp: '^#?LoadModule rewrite_module modules/mod_rewrite.so'
|
|
line: 'LoadModule rewrite_module modules/mod_rewrite.so'
|
|
state: present
|
|
notify: restart apache
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Allow .htaccess overrides (RHEL/CentOS)
|
|
replace:
|
|
path: /etc/httpd/conf/httpd.conf
|
|
regexp: 'AllowOverride None'
|
|
replace: 'AllowOverride All'
|
|
notify: restart apache
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Set MySQL root password (Debian/Ubuntu)
|
|
mysql_user:
|
|
name: root
|
|
host: "{{ item }}"
|
|
password: "{{ mysql_root_password }}"
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
|
state: present
|
|
check_implicit_admin: yes
|
|
loop: ['localhost', '127.0.0.1']
|
|
when: ansible_facts['os_family'] == "Debian"
|
|
|
|
- name: Set MariaDB root password (RHEL/CentOS)
|
|
mysql_user:
|
|
name: root
|
|
host: "{{ item }}"
|
|
password: "{{ mysql_root_password }}"
|
|
login_unix_socket: /var/lib/mysql/mysql.sock
|
|
state: present
|
|
check_implicit_admin: yes
|
|
loop: ['localhost', '127.0.0.1']
|
|
when: ansible_facts['os_family'] == "RedHat"
|
|
|
|
- name: Ensure Apache is listening on 80
|
|
lineinfile:
|
|
path: "{{ '/etc/apache2/ports.conf' if ansible_facts['os_family'] == 'Debian' else '/etc/httpd/conf/httpd.conf' }}"
|
|
regexp: '^Listen 80'
|
|
line: 'Listen 80'
|
|
state: present
|
|
|
|
handlers:
|
|
- name: restart apache
|
|
service:
|
|
name: "{{ 'apache2' if ansible_facts['os_family'] == 'Debian' else 'httpd' }}"
|
|
state: restarted |