wsl permission

This commit is contained in:
marito 2025-06-15 15:23:49 +08:00
parent 35a15697ad
commit 011ace41fb
2 changed files with 19 additions and 55 deletions

View File

@ -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
state: present

View File

@ -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')
when: project.database is defined and db_engine == 'mariadb'