Lenverge/roles/projects/tasks/configure_site.yml
2025-06-15 15:23:49 +08:00

63 lines
2.5 KiB
YAML

---
# ------------------ VALIDATION AND PERMISSION TASKS ------------------
- name: "Validate that project root '{{ project.project_root }}' exists"
ansible.builtin.stat:
path: "{{ project.project_root }}"
register: project_root_stat
- name: "Fail if project root directory does not exist"
ansible.builtin.fail:
msg: "VALIDATION FAILED for '{{ project.domain }}': The project_root '{{ project.project_root }}' does not exist. This path is required for Composer. Please create it or correct the path in Lenvi.yaml."
when: not project_root_stat.stat.exists or not project_root_stat.stat.isdir
- name: "Ensure correct ownership for project root directory (WSL Fix)"
ansible.builtin.file:
path: "{{ project.project_root }}"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_id }}"
recurse: yes
when: "'/mnt/' in project.project_root" # Only run this for projects on a Windows mount
- name: "Validate that document root '{{ project.document_root }}' exists"
ansible.builtin.stat:
path: "{{ project.document_root }}"
register: document_root_stat
- name: "Fail if document root directory does not exist"
ansible.builtin.fail:
msg: "VALIDATION FAILED for '{{ project.domain }}': The document_root '{{ project.document_root }}' does not exist. This path is required for Nginx. Please create it or correct the path in Lenvi.yaml."
when: not document_root_stat.stat.exists or not document_root_stat.stat.isdir
- name: "Check for an index file (index.php or index.html) in the document root"
ansible.builtin.find:
paths: "{{ project.document_root }}"
patterns: "index.php,index.html"
file_type: file
register: index_file_find
- name: "Fail if no index file is found"
ansible.builtin.fail:
msg: "VALIDATION FAILED for '{{ project.domain }}': No 'index.php' or 'index.html' was found in the document_root '{{ project.document_root }}'. Nginx requires an entry point file to serve the site."
when: index_file_find.matched == 0
# ------------------ CONFIGURATION TASKS ------------------
- name: "Create Nginx config for {{ project.domain }}"
ansible.builtin.template:
src: nginx-site.conf.j2
dest: "/etc/nginx/conf.d/{{ project.domain }}.conf"
owner: root
group: root
mode: '0644'
notify:
- Reload Nginx
- Reload PHP-FPM Services
- name: "Create project-specific MariaDB database '{{ project.database }}'"
community.mysql.mysql_db:
name: "{{ project.database }}"
state: present
login_unix_socket: /var/run/mysqld/mysqld.sock
when: project.database is defined and db_engine == 'mariadb'