From 011ace41fb8da83ff1c6864e123f24365619d0ff Mon Sep 17 00:00:00 2001 From: marito Date: Sun, 15 Jun 2025 15:23:49 +0800 Subject: [PATCH] wsl permission --- roles/common/tasks/main.yml | 40 +------------------------ roles/projects/tasks/configure_site.yml | 34 +++++++++++---------- 2 files changed, 19 insertions(+), 55 deletions(-) diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 8a9e53b..a6ae1fa 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -12,42 +12,4 @@ - name: "Add Ondřej PPA for PHP" ansible.builtin.apt_repository: repo: "ppa:ondrej/php" - state: present - -# ------------------ WSL Configuration for Correct File Permissions ------------------ -# This block automatically detects and configures WSL for a seamless experience. - -- name: "Check if running in a WSL environment" - ansible.builtin.stat: - path: /proc/version - register: proc_version_stat - -- name: "Set is_wsl fact based on /proc/version content" - ansible.builtin.set_fact: - is_wsl: "'Microsoft' in (lookup('file', '/proc/version') | default(''))" - when: proc_version_stat.stat.exists - -- name: "Ensure correct automount options are set in /etc/wsl.conf" - ansible.builtin.blockinfile: - path: /etc/wsl.conf - create: yes - owner: root - group: root - mode: '0644' - marker: "# {mark} ANSIBLE MANAGED BLOCK - LENVI AUTOMOUNT" - block: | - [automount] - enabled = true - options = "metadata,uid={{ ansible_user_uid }},gid={{ ansible_user_gid }},umask=22,fmask=11" - [user] - default = {{ ansible_user_id }} - register: wsl_conf_result - when: is_wsl | default(false) - -- name: "STOP PLAYBOOK: Force user to restart WSL if wsl.conf was changed" - ansible.builtin.fail: - msg: | - - 🛑 ACTION REQUIRED: WSL Configuration Was Updated! The playbook has configured /etc/wsl.conf to fix file permissions. You MUST restart WSL for this change to take effect. The playbook has been stopped. Please perform the following steps: 1. Close this terminal. 2. Open Windows PowerShell or CMD (not as admin). 3. Run the command: wsl --shutdown 4. Wait a few seconds, then re-open your WSL terminal and cd ~/Lenvi. 5. Re-run the Lenvi playbook: ansible-playbook playbook.yml -i inventory --ask-become-pass After restarting, your file permission issues will be permanently solved. - - when: wsl_conf_result.changed \ No newline at end of file + state: present \ No newline at end of file diff --git a/roles/projects/tasks/configure_site.yml b/roles/projects/tasks/configure_site.yml index e8d2e7e..967a217 100644 --- a/roles/projects/tasks/configure_site.yml +++ b/roles/projects/tasks/configure_site.yml @@ -1,5 +1,6 @@ --- -# ------------------ VALIDATION TASKS ------------------ +# ------------------ VALIDATION AND PERMISSION TASKS ------------------ + - name: "Validate that project root '{{ project.project_root }}' exists" ansible.builtin.stat: path: "{{ project.project_root }}" @@ -7,12 +8,17 @@ - name: "Fail if project root directory does not exist" ansible.builtin.fail: - msg: | - VALIDATION FAILED for site '{{ project.domain }}': - The project_root directory '{{ project.project_root }}' does not exist. - This path is required for Composer. Please create it or correct the path in Lenvi.yaml. + 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 }}" @@ -20,10 +26,7 @@ - name: "Fail if document root directory does not exist" ansible.builtin.fail: - msg: | - VALIDATION FAILED for site '{{ project.domain }}': - The document_root directory '{{ project.document_root }}' does not exist. - This path is required for Nginx. Please create it or correct the path in Lenvi.yaml. + 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" @@ -35,14 +38,13 @@ - name: "Fail if no index file is found" ansible.builtin.fail: - msg: | - VALIDATION FAILED for site '{{ 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. + 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 }} in conf.d" + +- name: "Create Nginx config for {{ project.domain }}" ansible.builtin.template: src: nginx-site.conf.j2 dest: "/etc/nginx/conf.d/{{ project.domain }}.conf" @@ -53,9 +55,9 @@ - Reload Nginx - Reload PHP-FPM Services -- name: "Create project-specific database '{{ project.database }}'" +- 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' or db_engine == 'mysql') \ No newline at end of file + when: project.database is defined and db_engine == 'mariadb' \ No newline at end of file