From 816ec1f32b632c6593b1e575a15c4f86fc03b018 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Tue, 15 Oct 2024 20:26:27 +0200 Subject: [PATCH] Tentativo di aggiustamento dell'utente su cui applicare le modifiche. --- roles/nix/defaults/main.yml | 1 + roles/nix/tasks/configuration.yml | 52 +++++++++++++++++++++------ roles/zsh/defaults/main.yml | 1 + roles/zsh/tasks/config/main.yml | 59 +++++++++++++++++++++++-------- 4 files changed, 87 insertions(+), 26 deletions(-) diff --git a/roles/nix/defaults/main.yml b/roles/nix/defaults/main.yml index acd7660..169b22c 100644 --- a/roles/nix/defaults/main.yml +++ b/roles/nix/defaults/main.yml @@ -1,2 +1,3 @@ --- +additional_user: syntaxerrormmm dotfdir: "{{ lookup('ansible.builtin.env', 'HOME' ) }}/.dotfiles" diff --git a/roles/nix/tasks/configuration.yml b/roles/nix/tasks/configuration.yml index 11790d3..ec5e441 100644 --- a/roles/nix/tasks/configuration.yml +++ b/roles/nix/tasks/configuration.yml @@ -1,15 +1,45 @@ --- # Configuring the nix installation. -- name: Adding user to nix-users - ansible.builtin.user: - name: "{{ ansible_user }}" - groups: nix-users - append: true - become: true +- name: Manipulation over {{ additional_user }} + when: ansible_user_id == 'root' + tags: + - nix + - nix-config + block: -- name: Adding configuration to local user - ansible.builtin.file: - src: "{{ dotfdir }}/nix" - dest: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/nix" - state: link + - name: Adding user to nix-users + ansible.builtin.user: + name: "{{ additional_user }}" + groups: nix-users + append: true + become_user: root + become: true + + - name: Adding configuration to local user + ansible.builtin.file: + src: "{{ dotfdir }}/nix" + dest: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/nix" + state: link + become_user: "{{ additional_user }}" + become: true + +- name: Manipulation over {{ ansible_user_id }} + when: ansible_user_id != 'root' + tags: + - nix + - nix-config + block: + + - name: Adding user to nix-users + ansible.builtin.user: + name: "{{ ansible_user }}" + groups: nix-users + append: true + become: true + + - name: Adding configuration to local user + ansible.builtin.file: + src: "{{ dotfdir }}/nix" + dest: "{{ lookup('ansible.builtin.env', 'HOME') }}/.config/nix" + state: link diff --git a/roles/zsh/defaults/main.yml b/roles/zsh/defaults/main.yml index 1f4bd2f..22158e4 100644 --- a/roles/zsh/defaults/main.yml +++ b/roles/zsh/defaults/main.yml @@ -1,2 +1,3 @@ --- +additional_user: syntaxerrormmm dotfdir: "{{ lookup('ansible.builtin.env', 'HOME') }}/.dotfiles" diff --git a/roles/zsh/tasks/config/main.yml b/roles/zsh/tasks/config/main.yml index 5a7d4a5..68d3759 100644 --- a/roles/zsh/tasks/config/main.yml +++ b/roles/zsh/tasks/config/main.yml @@ -4,21 +4,50 @@ - name: Fixing base settings ansible.builtin.include_tasks: "{{ ansible_os_family | lower }}.yml" -- name: Set zsh as default shell for user - ansible.builtin.user: - name: "{{ ansible_user }}" - shell: /usr/bin/zsh - become_user: root +- name: Applying modifications to {{ additional_user }} + when: ansible_user_id == 'root' become: true + block: -- name: Creating personal folder for customization - ansible.builtin.file: - path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zsh/conf.d" - state: directory - mode: '0755' + - name: Set zsh as default shell for user + ansible.builtin.user: + name: "{{ additional_user }}" + shell: /usr/bin/zsh + become_user: root + + - name: Creating personal folder for customization + ansible.builtin.file: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zsh/conf.d" + state: directory + mode: '0755' + become_user: "{{ additional_user }}" + + - name: Linking main file + ansible.builtin.file: + src: "{{ dotfdir }}/zshrc" + dest: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zshrc" + state: link + become_user: "{{ additional_user }}" -- name: Linking main file - ansible.builtin.file: - src: "{{ dotfdir }}/zshrc" - dest: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zshrc" - state: link +- name: Applying results to {{ ansible_user_id }} + when: ansible_user_id != 'root' + block: + + - name: Set zsh as default shell for user + ansible.builtin.user: + name: "{{ ansible_user_id }}" + shell: /usr/bin/zsh + become_user: root + become: true + + - name: Creating personal folder for customization + ansible.builtin.file: + path: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zsh/conf.d" + state: directory + mode: '0755' + + - name: Linking main file + ansible.builtin.file: + src: "{{ dotfdir }}/zshrc" + dest: "{{ lookup('ansible.builtin.env', 'HOME') }}/.zshrc" + state: link