Add P10k installation / configuration

This commit is contained in:
2025-01-09 17:15:23 +01:00
parent 19425ca130
commit 9a1412067c
21 changed files with 5656 additions and 80 deletions

View File

@ -1,4 +1,15 @@
---
- name: Include OS specific variables.
ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
vars:
params:
files:
- "{{ ansible_os_family }}.yml"
- "{{ ansible_system }}.yml"
- other-os.yml
paths:
- 'vars'
# Make sure zsh is installed and set to the user's default shell.
- name: "OMZ | include zsh.yml tasks."
include_tasks: "zsh.yml"
@ -24,7 +35,7 @@
- "configure"
- "configureohmyzsh"
# Finally, add exports etc to .zshrc /last/ (i.e. so they get added to whaterver
# Add exports etc to .zshrc /last/ (i.e. so they get added to whaterver
# .zshrc exists.
- name: "OMZ | include zsh-zshrc.yml tasks."
include_tasks: zsh-zshrc.yml
@ -32,3 +43,17 @@
- "zsh"
- "configure"
- "configurezsh"
# install and configure PowerLevel10k
- name: Include p10k prompt style variables.
ansible.builtin.include_vars: "{{ p10k_style[p10k_prompt_style] }}.yml"
- name: Install p10k
ansible.builtin.include_tasks: "p10k-install.yml"
- name: Install p10k recommanded fonts
ansible.builtin.include_tasks: "p10k-fonts.yml"
- name: Configure p10k
ansible.builtin.include_tasks: "p10k-configure.yml"

View File

@ -1,7 +1,12 @@
---
- name: "OMZ | establish install location."
set_fact:
omz_install_path: "{{ ansible_env.HOME }}/{{ omz_install_directory }}"
omz_install_path: >
{% if user == 'root' %}
/root/.{{ omz_install_directory }}
{% else %}
/home/{{ omz_user.name }}/{{ omz_install_directory }}
{% endif %}
- name: "OMZ | clone Oh My ZSH repo for user."
git:

16
tasks/p10k-configure.yml Normal file
View File

@ -0,0 +1,16 @@
---
- name: Set zsh as default shell
ansible.builtin.user:
name: "{{ item }}"
shell: "{{ zsh_bin_path }}"
become: true
loop: "{{ p10k_users }}"
- name: Setup powerlevel10k
ansible.builtin.template:
src: "p10k-{{ p10k_style[p10k_prompt_style] }}.zsh.j2"
dest: "{{ item['home'] }}/.p10k.zsh"
owner: "{{ item['name'] }}"
group: "{{ item['group'] }}"
mode: '0644'
loop: "{{ p10k_users_information }}"

19
tasks/p10k-fonts.yml Normal file
View File

@ -0,0 +1,19 @@
---
- name: Create fonts directory
ansible.builtin.file:
path: "{{ fonts_path }}"
mode: '0755'
state: directory
become: true
- name: Copy powerlevel10k recommanded fonts
ansible.builtin.copy:
src: "fonts/{{ item }}"
dest: "{{ fonts_path }}/{{ item }}"
mode: '0644'
become: true
loop:
- MesloLGS NF Bold Italic.ttf
- MesloLGS NF Bold.ttf
- MesloLGS NF Italic.ttf
- MesloLGS NF Regular.ttf

88
tasks/p10k-install.yml Normal file
View File

@ -0,0 +1,88 @@
---
# Install powerlevel10k
- name: Ensure dependencies are installed.
ansible.builtin.package:
name: "{{ p10k_dependencies }}"
state: present
become: true
when: p10k_dependencies
- name: Get ZSH version
ansible.builtin.shell: "set -o pipefail; zsh --version | cut -d ' ' -f2 | cut -c1-3"
args:
executable: /bin/bash
check_mode: no
changed_when: false
register: zsh_version
- name: Powerlevel10k works only with ZSH >= 5.1
ansible.builtin.fail:
msg: "You are using ZSH version {{ zsh_version.stdout }}. The minimum required version for Powerlevel10k is 5.1"
when: zsh_version.stdout|float < 5.1
- name: Get users information
ansible.builtin.user:
name: "{{ item }}"
state: present
register: p10k_users_register
loop: "{{ p10k_users }}"
- name: Extract only 'name', 'home' and 'group' fields from users information
ansible.builtin.set_fact:
p10k_users_information: "{{ p10k_users_information | default([]) + [{'name': item['name'], 'home': item['home'], 'group': item['group']}] }}"
no_log: true
loop: "{{ p10k_users_register.results }}"
- name: Install powerlevel10k.
ansible.builtin.git:
repo: "{{ p10k_repository_url }}"
dest: "{{ item['home'] }}/{{ p10k_path[zsh_plugin] | default('~/powerlevel10k', True) }}"
depth: '1'
update: no
version: 'master'
loop: "{{ p10k_users_information }}"
- name: Setup powerlevel10k file permissions.
ansible.builtin.file:
path: "{{ item['home'] }}/{{ p10k_path[zsh_plugin] | default('~/powerlevel10k', True) }}"
owner: "{{ item['name'] }}"
group: "{{ item['group'] }}"
recurse: yes
loop: "{{ p10k_users_information }}"
- name: Add powerlevel10k to zsh plugin
ansible.builtin.lineinfile:
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
regexp: "{{ p10k_zshrc_config[zsh_plugin]['regexp'] }}"
line: "{{ p10k_zshrc_config[zsh_plugin]['line'] }}"
owner: "{{ item['name'] }}"
group: "{{ item['group'] }}"
mode: '0644'
create: yes
loop: "{{ p10k_users_information }}"
- name: Enable powerlevel10 instant prompt
ansible.builtin.blockinfile:
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
owner: "{{ item['name'] }}"
group: "{{ item['group'] }}"
block: |
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
insertbefore: BOF
marker_begin: "BEGIN P10K INSTANT PROMPT"
marker_end: "END P10K INSTANT PROMPT"
loop: "{{ p10k_users_information }}"
- name: Enable powerlevel10k config file
ansible.builtin.blockinfile:
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
owner: "{{ item['name'] }}"
group: "{{ item['group'] }}"
block: |
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
insertafter: EOF
marker_begin: "BEGIN P10K CONFIG FILE"
marker_end: "END P10K CONFIG FILE"
loop: "{{ p10k_users_information }}"