From 2e6e278fc4943d90f2ba275a88e66093c7794c7f Mon Sep 17 00:00:00 2001 From: marito Date: Sun, 15 Jun 2025 14:30:34 +0800 Subject: [PATCH] wsl permission --- README.md | 2 +- roles/common/tasks/main.yml | 54 ++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb747a0..e838fd4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ This is the most important step. Open the `Lenvi.yaml` file and define your enti **Example** `Lenvi.yaml`**:** ```yaml -db_engine: "mariadb" #mariadb, mysql post +db_engine: "mariadb" #mariadb, mysql or postgresql db_credentials:   user: "Lenvi" password: "secret" diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 492101b..16aed60 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -5,10 +5,62 @@ - software-properties-common - ca-certificates - apt-transport-https + - unzip state: present update_cache: yes - name: "Add Ondřej PPA for PHP" ansible.builtin.apt_repository: repo: "ppa:ondrej/php" - state: present \ No newline at end of file + 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. + 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