ansible/roles/shell/tasks/configure_user_shell.yml
ilia 579f0709ce Update Makefile and inventory configurations for improved task execution and organization
- Refactor Makefile to enhance command structure, including clearer descriptions and usage examples for targets related to development, inventory, and monitoring tasks.
- Update inventory files to ensure correct host configurations and user settings, including adjustments to ansible_user for specific hosts.
- Modify group_vars to streamline Tailscale configuration and ensure proper handling of authentication keys.

These changes improve the clarity and usability of the Makefile and inventory setup, facilitating smoother operations across the infrastructure.
2025-10-09 21:24:45 -04:00

104 lines
3.5 KiB
YAML

---
# Configure shell for a single user
# Variable: current_user - the username to configure
- name: "Get user information: {{ current_user }}"
ansible.builtin.getent:
database: passwd
key: "{{ current_user }}"
register: user_info
failed_when: false
- name: "Set user home directory: {{ current_user }}"
ansible.builtin.set_fact:
user_home: "{{ user_info.ansible_facts.getent_passwd[current_user][4] }}"
when: user_info.ansible_facts.getent_passwd[current_user] is defined
- name: Skip if user not found
ansible.builtin.debug:
msg: "User {{ current_user }} not found, skipping shell configuration"
when: user_info.ansible_facts.getent_passwd[current_user] is not defined
- name: Configure shell environment
when: user_info.ansible_facts.getent_passwd[current_user] is defined
block:
- name: "Set zsh as default shell: {{ current_user }}"
ansible.builtin.user:
name: "{{ current_user }}"
shell: /usr/bin/zsh
become: true
- name: "Install Oh My Zsh: {{ current_user }}"
become: true
become_user: "{{ current_user }}"
ansible.builtin.shell: sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" "" --unattended
args:
creates: "{{ user_home }}/.oh-my-zsh"
- name: "Clone Powerlevel10k theme: {{ current_user }}"
ansible.builtin.git:
repo: https://github.com/romkatv/powerlevel10k.git
dest: "{{ user_home }}/.oh-my-zsh/custom/themes/powerlevel10k"
version: master
depth: 1
update: false
become: true
become_user: "{{ current_user }}"
- name: "Install zsh plugins: {{ current_user }}"
ansible.builtin.git:
repo: "{{ item.repo }}"
dest: "{{ user_home }}/.oh-my-zsh/custom/plugins/{{ item.name }}"
version: master
depth: 1
update: false
become: true
become_user: "{{ current_user }}"
loop: "{{ zsh_plugins }}"
- name: "Deploy .zshrc: {{ current_user }}"
ansible.builtin.copy:
src: files/.zshrc
dest: "{{ user_home }}/.zshrc"
owner: "{{ current_user }}"
group: "{{ current_user }}"
mode: '0644'
become: true
- name: "Deploy Powerlevel10k configuration: {{ current_user }}"
ansible.builtin.copy:
src: files/.p10k.zsh
dest: "{{ user_home }}/.p10k.zsh"
owner: "{{ current_user }}"
group: "{{ current_user }}"
mode: '0644'
become: true
- name: "Ensure .local/bin directory exists: {{ current_user }}"
ansible.builtin.file:
path: "{{ user_home }}/.local/bin"
state: directory
owner: "{{ current_user }}"
group: "{{ current_user }}"
mode: '0755'
become: true
- name: "Deploy showapps script: {{ current_user }}"
ansible.builtin.copy:
src: files/showapps.sh
dest: "{{ user_home }}/.local/bin/showapps"
owner: "{{ current_user }}"
group: "{{ current_user }}"
mode: '0755'
become: true
- name: "Display post-installation instructions: {{ current_user }}"
ansible.builtin.debug:
msg:
- "=== Shell Configuration Complete for {{ current_user }} ==="
- "NOTE: Zsh has been set as the default shell."
- "To activate immediately, choose one of:"
- " 1. Log out and back in (recommended)"
- " 2. Run: exec zsh"
- " 3. Or simply run: zsh"
- "=========================================="