ansible/roles/shell/tasks/configure_user_shell.yml
ilia 83a5d988af
Some checks failed
CI / lint-and-test (pull_request) Successful in 58s
CI / ansible-validation (pull_request) Successful in 2m17s
CI / secret-scanning (pull_request) Successful in 53s
CI / dependency-scan (pull_request) Successful in 57s
CI / sast-scan (pull_request) Successful in 2m17s
CI / license-check (pull_request) Successful in 55s
CI / vault-check (pull_request) Successful in 2m20s
CI / playbook-test (pull_request) Successful in 2m16s
CI / container-scan (pull_request) Successful in 1m25s
CI / sonar-analysis (pull_request) Failing after 1m56s
CI / workflow-summary (pull_request) Successful in 50s
Fix: Update ansible-lint configuration to exclude specific paths and skip certain rules for improved linting flexibility
2025-12-14 21:04:45 -05:00

105 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"
- "=========================================="