WIP: Harmonizing the 2 roles i use into 1 big working
This commit is contained in:
@ -3,7 +3,8 @@
|
||||
omz_install_zsh: false
|
||||
|
||||
# User vars.
|
||||
omz_user: []
|
||||
zsh_users:
|
||||
- "{{ ansible_user_id }}"
|
||||
|
||||
# Oh My ZSH vars.
|
||||
omz_git_repository: "https://github.com/robbyrussell/oh-my-zsh.git"
|
||||
@ -33,14 +34,9 @@ omz_plugins: []
|
||||
# Powerlevel10k Git repository url
|
||||
p10k_repository_url: 'https://github.com/romkatv/powerlevel10k.git'
|
||||
|
||||
# Install p10k for the following linux users
|
||||
# Default: the linux user running Ansible
|
||||
p10k_users:
|
||||
- "{{ ansible_user_id }}"
|
||||
|
||||
# Zsh plugin used, zsh, ohmyzsh, prezto, Zim, etc..
|
||||
# All plugin names can be found here https://github.com/romkatv/powerlevel10k#installation
|
||||
zsh_plugin: zsh
|
||||
zsh_plugin: ohmyzsh
|
||||
|
||||
# Setup p10k theme to use
|
||||
# Valid values: lean, classic, rainbow, pure
|
||||
|
@ -1,26 +1,19 @@
|
||||
---
|
||||
- name: "OMZ | establish install location."
|
||||
set_fact:
|
||||
omz_install_path: >
|
||||
{% if omz_user.name == 'root' %}
|
||||
/root/.{{ omz_install_directory }}
|
||||
{% else %}
|
||||
/home/{{ omz_user.name }}/{{ omz_install_directory }}
|
||||
{% endif %}
|
||||
|
||||
- name: "OMZ | clone Oh My ZSH repo for user."
|
||||
git:
|
||||
repo: "{{ omz_git_repository }}"
|
||||
dest: "{{ omz_install_path }}"
|
||||
dest: "{{ item.ansible_facts.user_home }}/{{ omz_install_directory }}"
|
||||
update: "true"
|
||||
accept_hostkey: "true"
|
||||
version: "master"
|
||||
register: "omz_clone"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
||||
- name: "OMZ | set ownership on newly cloned repository."
|
||||
file:
|
||||
path: "{{ omz_install_path }}"
|
||||
owner: "{{ omz_user.name }}"
|
||||
group: "{{ omz_user.group }}"
|
||||
path: "{{ item.ansible_facts.user_home }}/{{ omz_install_directory }}"
|
||||
owner: "{{ item.item }}"
|
||||
group: "{{ item.item }}"
|
||||
recurse: "true"
|
||||
when: "omz_clone is changed"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
@ -6,9 +6,10 @@
|
||||
- name: "OMZ | template .zshrc into place if required."
|
||||
template:
|
||||
src: "{{ omz_zshrc_template }}"
|
||||
dest: "{{ omz_user_zshrc_path }}"
|
||||
owner: "{{ omz_user.name }}"
|
||||
group: "{{ omz_user.group }}"
|
||||
dest: "{{ item.ansible_facts.user_home }}/.zshrc"
|
||||
owner: "{{ item.item }}"
|
||||
group: "{{ item.item }}"
|
||||
backup: "{{ omz_zshrc_backup }}"
|
||||
force: "{{ omz_zshrc_force }}"
|
||||
when: "omz_zshrc_create"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
@ -4,13 +4,13 @@
|
||||
name: "{{ item }}"
|
||||
shell: "{{ zsh_bin_path }}"
|
||||
become: true
|
||||
loop: "{{ p10k_users }}"
|
||||
loop: "{{ zsh_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'] }}"
|
||||
dest: "{{ item.ansible_facts.user_home }}/.p10k.zsh"
|
||||
owner: "{{ item.item }}"
|
||||
group: "{{ item.item }}"
|
||||
mode: '0644'
|
||||
loop: "{{ p10k_users_information }}"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
@ -20,52 +20,39 @@
|
||||
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) }}"
|
||||
dest: "{{ item.ansible_facts.user_home }}/{{ p10k_path }}"
|
||||
depth: '1'
|
||||
update: no
|
||||
version: 'master'
|
||||
loop: "{{ p10k_users_information }}"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
||||
- name: Setup powerlevel10k file permissions.
|
||||
- name: Setup powerlevel10k file permissions
|
||||
ansible.builtin.file:
|
||||
path: "{{ item['home'] }}/{{ p10k_path[zsh_plugin] | default('~/powerlevel10k', True) }}"
|
||||
owner: "{{ item['name'] }}"
|
||||
group: "{{ item['group'] }}"
|
||||
path: "{{ item.ansible_facts.user_home }}/{{ p10k_path }}"
|
||||
owner: "{{ item.item }}"
|
||||
group: "{{ item.item }}"
|
||||
recurse: yes
|
||||
loop: "{{ p10k_users_information }}"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
||||
- 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'] }}"
|
||||
path: "{{ item.ansible_facts.user_home }}/{{ p10k_path }}"
|
||||
regexp: ".*powerlevel10k.*"
|
||||
line: "source ~/{{ p10k_path }}/powerlevel10k.zsh-theme"
|
||||
owner: "{{ item.item }}"
|
||||
group: "{{ item.item }}"
|
||||
mode: '0644'
|
||||
create: yes
|
||||
loop: "{{ p10k_users_information }}"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
||||
- name: Enable powerlevel10 instant prompt
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
|
||||
owner: "{{ item['name'] }}"
|
||||
group: "{{ item['group'] }}"
|
||||
path: "{{ item.ansible_facts.user_home }}/{{ p10k_path }}"
|
||||
owner: "{{ item.item }}"
|
||||
group: "{{ item.item }}"
|
||||
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"
|
||||
@ -73,16 +60,16 @@
|
||||
insertbefore: BOF
|
||||
marker_begin: "BEGIN P10K INSTANT PROMPT"
|
||||
marker_end: "END P10K INSTANT PROMPT"
|
||||
loop: "{{ p10k_users_information }}"
|
||||
with_items: "{{ paths.results }}"
|
||||
|
||||
- name: Enable powerlevel10k config file
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ item['home'] }}/{{ p10k_zshrc_config[zsh_plugin]['zsh_file'] }}"
|
||||
owner: "{{ item['name'] }}"
|
||||
group: "{{ item['group'] }}"
|
||||
path: "{{ item.ansible_facts.user_home }}/{{ p10k_path }}"
|
||||
owner: "{{ item.item }}"
|
||||
group: "{{ item.item }}"
|
||||
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 }}"
|
||||
with_items: "{{ paths.results }}"
|
@ -1,64 +1,24 @@
|
||||
---
|
||||
# Global vars file for ansible-role-p10k
|
||||
|
||||
- name: Set home location for each users
|
||||
set_fact:
|
||||
user_home: "{{ '/root' if item == 'root' else '/home/' + item }}"
|
||||
with_items: "{{ zsh_users }}"
|
||||
register: paths
|
||||
|
||||
p10k_style:
|
||||
lean: 'lean'
|
||||
classic: 'classic'
|
||||
rainbow: 'rainbow'
|
||||
pure: 'rainbow'
|
||||
|
||||
p10k_path:
|
||||
zsh: 'powerlevel10k'
|
||||
ohmyzsh: '.oh-my-zsh/custom/themes/powerlevel10k'
|
||||
prezto: 'powerlevel10k'
|
||||
zim: 'powerlevel10k'
|
||||
antibody: 'powerlevel10k'
|
||||
antigen: 'powerlevel10k'
|
||||
zplug: 'powerlevel10k'
|
||||
zgen: 'powerlevel10k'
|
||||
zplugin: 'powerlevel10k'
|
||||
zinit: 'powerlevel10k'
|
||||
p10k_path: '.oh-my-zsh/custom/themes/powerlevel10k'
|
||||
|
||||
p10k_zshrc_config:
|
||||
zsh:
|
||||
regexp: '^source '
|
||||
line: 'source ~/powerlevel10k/powerlevel10k.zsh-theme'
|
||||
zsh_file: .zshrc
|
||||
ohmyzsh:
|
||||
regexp: '^ZSH_THEME='
|
||||
line: 'ZSH_THEME="powerlevel10k/powerlevel10k"'
|
||||
zsh_file: .zshrc
|
||||
prezto:
|
||||
regexp: '^zstyle :prezto:module:prompt theme'
|
||||
line: 'zstyle :prezto:module:prompt theme powerlevel10k'
|
||||
zsh_file: .zpreztorc
|
||||
zim:
|
||||
regexp: '^zmodule '
|
||||
line: 'zmodule romkatv/powerlevel10k'
|
||||
zsh_file: .zimrc
|
||||
antibody:
|
||||
regexp: '^antibody bundle '
|
||||
line: 'antibody bundle romkatv/powerlevel10k'
|
||||
zsh_file: .zshrc
|
||||
antigen:
|
||||
regexp: '^antigen theme '
|
||||
line: 'antigen theme romkatv/powerlevel10k'
|
||||
zsh_file: .zshrc
|
||||
zplug:
|
||||
regexp: '^zplug '
|
||||
line: 'zplug romkatv/powerlevel10k, as:theme, depth:1'
|
||||
zsh_file: .zshrc
|
||||
zgen:
|
||||
regexp: '^zgen load '
|
||||
line: 'zgen load romkatv/powerlevel10k powerlevel10k'
|
||||
zsh_file: .zshrc
|
||||
zplugin:
|
||||
regexp: '^zplugin ice depth=1; zplugin light'
|
||||
line: 'zplugin ice depth=1; zplugin light romkatv/powerlevel10k'
|
||||
zsh_file: .zshrc
|
||||
zinit:
|
||||
regexp: '^zinit ice depth=1; zinit light'
|
||||
line: 'zinit ice depth=1; zinit light romkatv/powerlevel10k'
|
||||
zsh_file: .zshrc
|
||||
regexp: '^ZSH_THEME='
|
||||
line: 'ZSH_THEME="powerlevel10k/powerlevel10k"'
|
||||
zsh_file: .zshrc
|
||||
|
||||
time_config:
|
||||
no:
|
||||
|
Reference in New Issue
Block a user