wsl permission

This commit is contained in:
marito 2025-06-15 14:30:34 +08:00
parent bcc77ad88e
commit 2e6e278fc4
2 changed files with 54 additions and 2 deletions

View File

@ -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"

View File

@ -5,6 +5,7 @@
- software-properties-common
- ca-certificates
- apt-transport-https
- unzip
state: present
update_cache: yes
@ -12,3 +13,54 @@
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.
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