From e24515d23227cbb831accf098ad4e631a9d07fcb Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Tue, 21 Nov 2023 19:37:31 +0100 Subject: [PATCH] feat: support btrfs subvolume for unix user's home dir --- defaults/default.yml | 1 + tasks/create_unix_user.yml | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/defaults/default.yml b/defaults/default.yml index e758271..64b93ea 100644 --- a/defaults/default.yml +++ b/defaults/default.yml @@ -23,6 +23,7 @@ unix_users: {} # private_keys: # - alice@alice-pc.ed25519.key # home: /home/alice +# btrfs: false # shell: /bin/bash # group: alice # groups: [] diff --git a/tasks/create_unix_user.yml b/tasks/create_unix_user.yml index 49a2569..d0ec5a9 100644 --- a/tasks/create_unix_user.yml +++ b/tasks/create_unix_user.yml @@ -4,6 +4,11 @@ ansible.builtin.set_fact: user_user_home: "{{ unix_user.value.home | default('/home/' + unix_user.key) }}" +- name: "Create btrfs volume for unix user: {{ unix_user.key }}" + community.general.btrfs_subvolume: + name: "{{ user_user_home }}" + when: unix_user.value.btrfs + - name: "Create unix user without additional groups and uid: {{ unix_user.key }}" ansible.builtin.user: name: "{{ unix_user.key }}" @@ -56,6 +61,23 @@ state: present when: unix_user.value.groups is defined and unix_user.value.uid is not defined +- name: "Adapt permissions and copy skel for unix user: {{ unix_user.key }}" + block: + - name: "Copy skel dir" + ansible.builtin.copy: + src: /etc/skel/ + dest: "{{ user_user_home }}" + remote_src: true + owner: "{{ unix_user.key }}" + group: "{{ unix_user.value.group | default('users') }}" + - name: "Change permission unix users home dir: {{ unix_user.key }}" + ansible.builtin.file: + path: "{{ user_user_home }}" + owner: "{{ unix_user.key }}" + group: "{{ unix_user.value.group | default('users') }}" + state: directory + when: unix_user.value.btrfs + - name: "Create .ssh directory for unix user: {{ unix_user.key }}" ansible.builtin.file: path: "{{ user_user_home }}/.ssh"