|
|
@@ -1,38 +1,41 @@
|
|
|
---
|
|
|
- name: Install PHP and MySQL on Debian-based systems
|
|
|
hosts: debian
|
|
|
- become: yes # Use privilege escalation to become the root user
|
|
|
+ become: yes
|
|
|
vars:
|
|
|
db_username: wordpress
|
|
|
db_password: wordpress
|
|
|
db_name: wordpress
|
|
|
+ site_url: debian-111
|
|
|
tasks:
|
|
|
- name: Update apt cache
|
|
|
ansible.builtin.apt:
|
|
|
update_cache: yes
|
|
|
|
|
|
- # These two will be needed to install mysqlclient
|
|
|
- - name: Install gcc, mariadb-dev, pkgconfig and pip3
|
|
|
- ansible.builtin.apt:
|
|
|
- name:
|
|
|
- - gcc # needed to compile
|
|
|
- - python3-dev # needed to compile
|
|
|
- - mariadb-dev
|
|
|
- - python3-pip
|
|
|
- - pkgconfig
|
|
|
- state: present
|
|
|
-
|
|
|
+ # Utilisés pour installer/compiler le package python mysqlclient
|
|
|
+ # - name: Install gcc, mariadb-dev, pkgconfig and pip3
|
|
|
+ # ansible.builtin.apt:
|
|
|
+ # name:
|
|
|
+ # - gcc # needed to compile
|
|
|
+ # - python3-dev # needed to compile
|
|
|
+ # # - mariadb-dev
|
|
|
+ # - python3-pip
|
|
|
+ # # - pkgconfig
|
|
|
+ # state: present
|
|
|
+
|
|
|
+ # Remarque : php 8.2 pour Debian Bookworm
|
|
|
- name: Install PHP
|
|
|
ansible.builtin.apt:
|
|
|
name:
|
|
|
- - php
|
|
|
- - php-fpm
|
|
|
- - php-iconv # for WordPress
|
|
|
- - php-mysqli # for WordPress/MySQL
|
|
|
- - php-phar # for wp-cli
|
|
|
- - php-json # for wp-cli
|
|
|
- - php-openssl # for wp-cli
|
|
|
- - php-curl # for wp-cli
|
|
|
+ - php8.2
|
|
|
+ - php8.2-fpm
|
|
|
+ - php8.2-iconv # for WordPress
|
|
|
+ - php8.2-mysqli # for WordPress/MySQL
|
|
|
+ - php8.2-phar # for wp-cli
|
|
|
+ # - php8.2-json # for wp-cli
|
|
|
+ # pas de package php8.2-openssl pour Debian Bookworm
|
|
|
+ # - php8.2-openssl # for wp-cli
|
|
|
+ - php8.2-curl # for wp-cli
|
|
|
state: present
|
|
|
|
|
|
- name: Install curl
|
|
|
@@ -40,6 +43,11 @@
|
|
|
name: curl
|
|
|
state: present
|
|
|
|
|
|
+ - name: Install Nginx
|
|
|
+ ansible.builtin.apt:
|
|
|
+ name: nginx
|
|
|
+ state: present
|
|
|
+
|
|
|
- name: Check if WordPress exists in /var/www/wordpress
|
|
|
stat:
|
|
|
path: /var/www/wordpress
|
|
|
@@ -63,31 +71,23 @@
|
|
|
command: tar -xzf /tmp/wordpress.tar.gz -C /var/www
|
|
|
when: wordpress_dir.stat.exists == False
|
|
|
|
|
|
- - name: Install Nginx
|
|
|
- ansible.builtin.apk:
|
|
|
- name: nginx
|
|
|
- state: present
|
|
|
-
|
|
|
- - name: Install MariaDB Server
|
|
|
- ansible.builtin.apk:
|
|
|
- name: mariadb
|
|
|
- state: present
|
|
|
-
|
|
|
- - name: Install MariaDB Client Tools
|
|
|
- ansible.builtin.apk:
|
|
|
- name: mariadb-client
|
|
|
+ - name: Install MariaDB Server & Client
|
|
|
+ ansible.builtin.apt:
|
|
|
+ name:
|
|
|
+ - mariadb-server
|
|
|
+ - mariadb-client
|
|
|
state: present
|
|
|
|
|
|
- - name: Start Nginx Service
|
|
|
- ansible.builtin.service:
|
|
|
- name: nginx
|
|
|
- state: started
|
|
|
- enabled: yes # Ensure the MySQL service starts on boot
|
|
|
+ # - name: Start Nginx Service
|
|
|
+ # ansible.builtin.service:
|
|
|
+ # name: nginx
|
|
|
+ # state: started
|
|
|
+ # enabled: yes # Ensure the MySQL service starts on boot
|
|
|
|
|
|
# Store mariadb status in a variable
|
|
|
# It'll be useful to conditionally run `/etc/init.d/mariadb setup`
|
|
|
- name: Check MariaDB status
|
|
|
- command: rc-service mariadb status
|
|
|
+ command: service mariadb status
|
|
|
register: mariadb_status
|
|
|
ignore_errors: yes
|
|
|
|
|
|
@@ -104,11 +104,11 @@
|
|
|
# when: mariadb_status.stdout.find('started') == -1
|
|
|
|
|
|
# Problem I had: it failed here after 1st run
|
|
|
- - name: MariaDB setup
|
|
|
- command: /etc/init.d/mariadb setup
|
|
|
- # run only if service is NOT running, that is, the output from
|
|
|
- # `rc-service mariadb status` doesn't contain `started`
|
|
|
- when: mariadb_status.stdout.find('started') == -1
|
|
|
+ # - name: MariaDB setup
|
|
|
+ # command: /etc/init.d/mariadb setup
|
|
|
+ # # run only if service is NOT running, that is, the output from
|
|
|
+ # # `rc-service mariadb status` doesn't contain `started`
|
|
|
+ # when: mariadb_status.stdout.find('started') == -1
|
|
|
|
|
|
- name: Start MariaDB Service
|
|
|
ansible.builtin.service:
|
|
|
@@ -116,10 +116,17 @@
|
|
|
state: started
|
|
|
enabled: yes # Ensure the MariaDB service starts on boot
|
|
|
|
|
|
- - name: Install mysqlclient
|
|
|
- ansible.builtin.pip:
|
|
|
- name: mysqlclient
|
|
|
+ # On ne va pas le faire avec pip mais avec apt
|
|
|
+ # - name: Install mysqlclient
|
|
|
+ # ansible.builtin.pip:
|
|
|
+ # name: mysqlclient
|
|
|
+ # state: present
|
|
|
+
|
|
|
+ - name: Installer le client MySQL pour Python
|
|
|
+ ansible.builtin.apt:
|
|
|
+ name: python3-mysqldb
|
|
|
state: present
|
|
|
+ update_cache: yes
|
|
|
|
|
|
- name: create MySQL database
|
|
|
mysql_db:
|
|
|
@@ -159,29 +166,30 @@
|
|
|
mode: 0644
|
|
|
when: wp_config.stat.exists == False
|
|
|
|
|
|
- # Check that default.conf.bak exists
|
|
|
- - name: Check if default.conf.bak exists
|
|
|
- ansible.builtin.stat:
|
|
|
- path: /etc/nginx/http.d/default.conf.bak
|
|
|
- register: default_conf_bak
|
|
|
-
|
|
|
- # Backup nginx default vhost config if not already backed up
|
|
|
- - name: Backup default Nginx vhost config
|
|
|
- command: mv /etc/nginx/http.d/default.conf /etc/nginx/http.d/default.conf.bak
|
|
|
- when: default_conf_bak.stat.exists == False
|
|
|
-
|
|
|
# Overwrite default vhost config with our own
|
|
|
- - name: Write new vhost config
|
|
|
+ - name: Write WordPress vhost config
|
|
|
ansible.builtin.template:
|
|
|
src: templates/nginx-wordpress.conf.j2
|
|
|
- dest: /etc/nginx/http.d/nginx-wordpress.conf
|
|
|
+ dest: /etc/nginx/sites-available/nginx-wordpress.conf
|
|
|
owner: root
|
|
|
group: root
|
|
|
mode: 0644
|
|
|
|
|
|
+ - name: Create symbolic link to enable the vhost
|
|
|
+ ansible.builtin.file:
|
|
|
+ src: /etc/nginx/sites-available/nginx-wordpress.conf
|
|
|
+ dest: /etc/nginx/sites-enabled/nginx-wordpress.conf
|
|
|
+ state: link
|
|
|
+
|
|
|
+ # remove `default` symlink from sites-enabled
|
|
|
+ - name: Remove default symlink from sites-enabled
|
|
|
+ ansible.builtin.file:
|
|
|
+ path: /etc/nginx/sites-enabled/default
|
|
|
+ state: absent
|
|
|
+
|
|
|
- name: Restart PHP-FPM
|
|
|
ansible.builtin.service:
|
|
|
- name: php-fpm81
|
|
|
+ name: php8.2-fpm
|
|
|
state: restarted
|
|
|
enabled: yes # Ensure the PHP-FPM service starts on boot
|
|
|
|
|
|
@@ -210,13 +218,16 @@
|
|
|
|
|
|
# Check if WordPress is installed
|
|
|
- name: Check if WordPress is installed
|
|
|
- command: wp core is-installed --path=/var/www/wordpress
|
|
|
+ command: sudo -u debian wp core is-installed --path=/var/www/wordpress
|
|
|
register: wp_installed
|
|
|
ignore_errors: yes
|
|
|
|
|
|
# WP core install (cwd: /var/www/wordpress)
|
|
|
- name: Install WordPress
|
|
|
- command: wp core install --url=192.168.1.85 --title=My\ Blog --admin_user=admin --admin_password=admin --admin_email=benoithubert@gmail.com
|
|
|
+ command: sudo -u debian wp core install --url={{ site_url }} --title=My\ Blog --admin_user=admin --admin_password=admin --admin_email=benoithubert@gmail.com
|
|
|
+ # WP-CLI complains if we run it as root, so we become a regular user
|
|
|
+ become: no
|
|
|
+ # Shou
|
|
|
args:
|
|
|
chdir: /var/www/wordpress
|
|
|
when: wp_installed.rc != 0
|