2025-11-16 19:41:07 +01:00
|
|
|
# Fichier: install_php_83_symfony_pgsql.yml
|
2025-07-16 13:43:52 +02:00
|
|
|
|
|
|
|
|
- name: Deploy application
|
2025-07-17 11:36:14 +02:00
|
|
|
hosts: webservers
|
|
|
|
|
become: true
|
|
|
|
|
gather_facts: true
|
2025-07-16 13:43:52 +02:00
|
|
|
|
|
|
|
|
vars:
|
2025-11-16 19:41:07 +01:00
|
|
|
db_name: "e-cosplay"
|
|
|
|
|
db_user: "e-cosplay"
|
|
|
|
|
db_password: "e-cosplay"
|
|
|
|
|
redis_password: "e-cosplay"
|
2025-11-16 19:44:31 +01:00
|
|
|
redis_port: "20502"
|
2025-07-16 13:43:52 +02:00
|
|
|
tasks:
|
2025-09-27 13:37:42 +02:00
|
|
|
- name: Installer le support ACL pour corriger les permissions de 'become_user'
|
|
|
|
|
ansible.builtin.apt:
|
|
|
|
|
name: acl
|
|
|
|
|
state: present
|
|
|
|
|
update_cache: true
|
|
|
|
|
when: ansible_os_family == "Debian"
|
|
|
|
|
|
2025-07-16 13:50:41 +02:00
|
|
|
- name: Installation des dépendances pour le module Ansible PostgreSQL
|
|
|
|
|
ansible.builtin.apt:
|
|
|
|
|
name: python3-psycopg2
|
|
|
|
|
state: present
|
|
|
|
|
update_cache: true
|
|
|
|
|
when: ansible_os_family == "Debian"
|
2025-07-16 14:16:23 +02:00
|
|
|
|
2025-07-16 13:50:41 +02:00
|
|
|
- name: Installation de PHP 8.3 et PHP 8.3-FPM avec les dépendances
|
|
|
|
|
ansible.builtin.apt:
|
|
|
|
|
name:
|
|
|
|
|
- php8.3
|
|
|
|
|
- php8.3-fpm
|
|
|
|
|
- php8.3-cli
|
|
|
|
|
- php8.3-common
|
2025-07-17 11:36:14 +02:00
|
|
|
- php8.3-mysql
|
|
|
|
|
- php8.3-pgsql
|
|
|
|
|
- php8.3-xml
|
|
|
|
|
- php8.3-mbstring
|
|
|
|
|
- php8.3-zip
|
|
|
|
|
- php8.3-intl
|
|
|
|
|
- php8.3-gd
|
|
|
|
|
- php8.3-curl
|
|
|
|
|
- php8.3-pdo
|
|
|
|
|
- php8.3-opcache
|
|
|
|
|
- php8.3-bcmath
|
|
|
|
|
- php8.3-redis
|
|
|
|
|
- php8.3-imagick
|
|
|
|
|
- ffmpeg
|
2025-07-16 13:50:41 +02:00
|
|
|
state: present
|
|
|
|
|
when: ansible_os_family == "Debian"
|
2025-07-16 14:16:23 +02:00
|
|
|
|
|
|
|
|
- name: Démarrage et activation du service PHP 8.3 FPM
|
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
|
name: php8.3-fpm
|
|
|
|
|
state: started
|
|
|
|
|
enabled: yes
|
|
|
|
|
when: ansible_os_family == "Debian"
|
2025-07-16 14:02:46 +02:00
|
|
|
- name: Créer le fichier .env.local avec les secrets de production
|
|
|
|
|
ansible.builtin.copy:
|
|
|
|
|
content: |
|
|
|
|
|
APP_ENV=prod
|
|
|
|
|
VITE_LOAD=1
|
|
|
|
|
DATABASE_URL="postgresql://{{ db_user }}:{{ db_password }}@127.0.0.1:5432/{{ db_name }}?serverVersion=16&charset=utf8"
|
|
|
|
|
REDIS_DSN="redis://{{ redis_password }}@127.0.0.1:{{ redis_port }}"
|
2025-07-16 14:16:23 +02:00
|
|
|
REDIS_URL="redis://{{ redis_password }}@127.0.0.1:{{ redis_port }}"
|
|
|
|
|
MESSENGER_TRANSPORT_DSN="redis://{{ redis_password }}@127.0.0.1:{{ redis_port }}/messages"
|
|
|
|
|
APP_SECRET=939bbc67038c2e2d1232d86fc605bf2f
|
2025-07-17 13:41:24 +02:00
|
|
|
REAL_MAIL=1
|
2025-07-23 09:35:59 +02:00
|
|
|
VAULT_ADDR=http://127.0.0.1:8200
|
|
|
|
|
VAULT_TOKEN=hvs.QLpUdiptXtSPo5Qf7i2nn2Xz
|
2025-10-01 13:58:50 +02:00
|
|
|
APP_DEBUG=true
|
2025-10-07 14:28:09 +02:00
|
|
|
MAILER_DSN=ses+smtp://AKIAWTT2T22CWBRBBDYN:BBdgb6KxRQ8mNcpWFJsZCJxbSGNdgLhKFiITMErfBlQP@default?region=eu-west-3
|
2025-07-23 09:36:27 +02:00
|
|
|
dest: "{{ path }}/.env.local"
|
2025-07-16 14:02:46 +02:00
|
|
|
when: ansible_os_family == "Debian"
|
2025-07-16 14:16:23 +02:00
|
|
|
|
2025-07-17 11:36:14 +02:00
|
|
|
# --- Initial creation of essential directories with correct ownership ---
|
|
|
|
|
# These directories should exist before composer runs, but composer might create subdirs.
|
|
|
|
|
- name: Ensure app/var and public/media directories exist with correct owner/group
|
2025-07-16 14:16:23 +02:00
|
|
|
ansible.builtin.file:
|
2025-07-17 11:36:14 +02:00
|
|
|
path: "{{ item }}"
|
|
|
|
|
owner: bot # Assuming 'bot' is your deployment user
|
2025-07-16 14:16:23 +02:00
|
|
|
group: www-data
|
2025-07-17 11:36:14 +02:00
|
|
|
mode: '0775' # Allow 'bot' and 'www-data' to read/write/execute
|
2025-07-16 14:16:23 +02:00
|
|
|
state: directory
|
2025-07-17 11:36:14 +02:00
|
|
|
recurse: yes # Important to ensure subdirectories created by previous deploys also get permissions
|
|
|
|
|
loop:
|
|
|
|
|
- "{{ path }}/var"
|
|
|
|
|
- "{{ path }}/var/log" # Specific for log, though var/log might be created by composer later
|
|
|
|
|
- "{{ path }}/public/media" # For uploads
|
2025-07-16 14:16:23 +02:00
|
|
|
|
2025-07-16 14:09:13 +02:00
|
|
|
- name: Exécuter 'composer install' dans le répertoire de l'application
|
|
|
|
|
ansible.builtin.command: composer install --no-dev --optimize-autoloader
|
2025-07-17 11:36:14 +02:00
|
|
|
become: false # Run as the connection user (e.g., 'bot')
|
2025-07-16 14:09:13 +02:00
|
|
|
args:
|
2025-07-17 11:36:14 +02:00
|
|
|
chdir: "{{ path }}"
|
2025-07-16 14:09:13 +02:00
|
|
|
when: ansible_os_family == "Debian"
|
|
|
|
|
|
2025-07-17 11:36:14 +02:00
|
|
|
# --- POST-COMPOSER PERMISSION FIXES ---
|
|
|
|
|
# This is crucial because composer creates var/cache as the `become: false` user
|
|
|
|
|
- name: Set correct permissions for Symfony cache and logs directories
|
|
|
|
|
ansible.builtin.file:
|
|
|
|
|
path: "{{ item }}"
|
|
|
|
|
owner: bot
|
|
|
|
|
group: www-data
|
|
|
|
|
mode: '0775' # rwx for owner and group, rx for others
|
|
|
|
|
state: directory
|
|
|
|
|
recurse: yes # Apply to all contents
|
|
|
|
|
loop:
|
|
|
|
|
- "{{ path }}/var/cache"
|
|
|
|
|
- "{{ path }}/var/log"
|
|
|
|
|
# For web-writable directories created by the app itself (e.g., uploads), you might set ACLs
|
|
|
|
|
# or chown to www-data and then your user gets access via group membership.
|
|
|
|
|
|
|
|
|
|
# Alternative for cache/log permissions using ACLs (more robust for mixed ownership)
|
|
|
|
|
# This requires 'acl' package installed (which you already do).
|
|
|
|
|
# Use this if 'bot' needs to own, but www-data needs to write.
|
|
|
|
|
- name: Set ACLs for Symfony cache and logs (recommended for web-writable dirs)
|
|
|
|
|
ansible.builtin.acl:
|
|
|
|
|
path: "{{ item }}"
|
|
|
|
|
entity: www-data
|
|
|
|
|
etype: group
|
|
|
|
|
permissions: rwx
|
|
|
|
|
state: present
|
|
|
|
|
recursive: yes
|
|
|
|
|
default: yes # Apply default ACLs for new files/dirs within
|
|
|
|
|
loop:
|
|
|
|
|
- "{{ path }}/var/cache"
|
|
|
|
|
- "{{ path }}/var/log"
|
|
|
|
|
when: ansible_os_family == "Debian" # ACLs are Linux-specific
|
|
|
|
|
|
2025-07-16 14:09:13 +02:00
|
|
|
- name: Exécuter bun install dans le répertoire de l application
|
|
|
|
|
ansible.builtin.command: bun install
|
|
|
|
|
become: false
|
|
|
|
|
args:
|
|
|
|
|
chdir: "{{ path }}"
|
|
|
|
|
when: ansible_os_family == "Debian"
|
|
|
|
|
|
|
|
|
|
- name: Exécuter bun build dans le répertoire de l application
|
|
|
|
|
ansible.builtin.command: bun run build
|
|
|
|
|
become: false
|
|
|
|
|
args:
|
|
|
|
|
chdir: "{{ path }}"
|
|
|
|
|
when: ansible_os_family == "Debian"
|
2025-07-16 14:16:23 +02:00
|
|
|
|
|
|
|
|
- name: Supervisor config
|
|
|
|
|
ansible.builtin.template:
|
|
|
|
|
src: supervisor.j2
|
2025-11-16 19:41:07 +01:00
|
|
|
dest: "/etc/supervisor/conf.d/e-cosplay.conf"
|
2025-07-16 14:16:23 +02:00
|
|
|
mode: '0644'
|
|
|
|
|
|
|
|
|
|
- name: Reread Supervisor configuration
|
2025-07-17 11:36:14 +02:00
|
|
|
ansible.builtin.command: supervisorctl reread
|
|
|
|
|
changed_when: true # Always mark as changed, as output is not always useful for idempotency
|
2025-07-16 14:16:23 +02:00
|
|
|
|
|
|
|
|
- name: Update Supervisor (add/remove updated programs)
|
2025-07-17 11:36:14 +02:00
|
|
|
ansible.builtin.command: supervisorctl update
|
|
|
|
|
changed_when: true
|
2025-07-16 14:16:23 +02:00
|
|
|
|
|
|
|
|
- name: Purger la base de données Redis
|
|
|
|
|
ansible.builtin.command: "redis-cli -p {{ redis_port }} -a {{ redis_password }} FLUSHALL"
|
|
|
|
|
when: ansible_os_family == "Debian"
|
|
|
|
|
|
|
|
|
|
- name: Generate Caddy site configuration
|
|
|
|
|
ansible.builtin.template:
|
|
|
|
|
src: caddy.j2
|
2025-11-16 19:41:07 +01:00
|
|
|
dest: "/etc/caddy/sites/e-cosplay.conf"
|
2025-07-16 14:16:23 +02:00
|
|
|
mode: '0644'
|
|
|
|
|
|
|
|
|
|
- name: Reload Caddy to apply new configuration
|
2025-07-17 11:36:14 +02:00
|
|
|
ansible.builtin.systemd:
|
2025-07-16 14:16:23 +02:00
|
|
|
name: caddy
|
|
|
|
|
state: reloaded
|
|
|
|
|
enabled: yes
|
2025-10-01 13:57:10 +02:00
|
|
|
- name: Exécuter doctrine:migration:migrate dans le répertoire de l application
|
2025-10-01 14:03:09 +02:00
|
|
|
ansible.builtin.command: php bin/console doctrine:migrations:migrate --no-interaction
|
2025-10-01 13:57:10 +02:00
|
|
|
become: false
|
|
|
|
|
args:
|
|
|
|
|
chdir: "{{ path }}"
|
|
|
|
|
when: ansible_os_family == "Debian"
|
2025-07-16 14:16:23 +02:00
|
|
|
- name: Exécuter cache:clear dans le répertoire de l application
|
|
|
|
|
ansible.builtin.command: php bin/console cache:clear
|
|
|
|
|
become: false
|
|
|
|
|
args:
|
|
|
|
|
chdir: "{{ path }}"
|
|
|
|
|
when: ansible_os_family == "Debian"
|
2025-07-17 11:36:14 +02:00
|
|
|
|
2025-07-16 15:09:01 +02:00
|
|
|
- name: Exécuter liip:imagine:cache:remove dans le répertoire de l application
|
|
|
|
|
ansible.builtin.command: php bin/console liip:imagine:cache:remove
|
|
|
|
|
become: false
|
|
|
|
|
args:
|
|
|
|
|
chdir: "{{ path }}"
|
2025-10-01 13:53:19 +02:00
|
|
|
- name: Set correct permissions for Symfony cache and logs directories
|
2025-07-16 14:16:23 +02:00
|
|
|
ansible.builtin.file:
|
2025-10-01 13:53:19 +02:00
|
|
|
path: "{{ item }}"
|
2025-07-17 11:36:14 +02:00
|
|
|
owner: bot
|
2025-07-16 14:16:23 +02:00
|
|
|
group: www-data
|
2025-10-01 13:55:19 +02:00
|
|
|
mode: '0777' # rwx for owner and group, rx for others
|
2025-07-16 14:16:23 +02:00
|
|
|
state: directory
|
2025-10-01 13:53:19 +02:00
|
|
|
recurse: yes # Apply to all contents
|
|
|
|
|
loop:
|
|
|
|
|
- "{{ path }}/var/cache"
|
|
|
|
|
- "{{ path }}/var/log"
|
|
|
|
|
- "{{ path }}/public/media"
|