ctorgalson.oh-my-zsh
Ansible Role: Oh My ZSH
This is a simple Ansible role that helps set up and configure Oh My Zsh on Fedora, Ubuntu, or MacOS, and it also works on many other Unix-like systems. Here are the tasks it performs:
- Installs and sets up Zsh:
- Checks that Zsh is installed,
- Makes it the default shell for the user you choose.
- Installs Oh My Zsh for each user listed (default location is
~/.oh-my-zsh
). - Configures Zsh, optionally creating a
.zshrc
file for each specified user. - Alternatively, adds lines to the existing
.zshrc
files of individual users.
Role Variables
Variable Name | Default Value | Description |
---|---|---|
omz_install_zsh |
false |
Decides if Zsh should be installed. |
omz_user |
[] |
The user for whom to install/configure Oh My Zsh. |
omz_user.name |
- |
Name of the user. |
omz_user.group |
- |
Group of the user. |
omz_user.settings |
- |
Additional settings like variable exports or aliases. Used if omz_zshrc_create is true. |
omz_git_repository |
https://github.com/robbyrussell/oh-my-zsh.git |
Git repository to clone Oh My Zsh from. |
omz_install_directory |
.oh-my-zsh |
Directory name to clone Oh My Zsh into. |
omz_zshrc_create |
true |
Whether to create a new .zshrc file. |
omz_zshrc_template |
templates/zshrc.zsh-template.j2 |
Template for creating the user's .zshrc . |
omz_zshrc_backup |
true |
Whether to back up existing .zshrc files. |
omz_zsh_theme |
robbyrussell |
Zsh theme to use. |
omz_case_sensitive |
false |
Case sensitivity setting. |
omz_hyphen_insensitive |
false |
Hyphen sensitivity setting. |
omz_disable_auto_update |
false |
Auto-update setting. |
omz_update_zsh_days |
13 |
Days between updates for Zsh. |
omz_disable_ls_colors |
false |
Setting to disable ls colors. |
omz_disable_auto_title |
false |
Auto-title setting. |
omz_enable_correction |
false |
Enable correction for commands. |
omz_completion_waiting_dots |
false |
Dots for waiting completion. |
omz_disable_untracked_files_dirty |
false |
Setting for untracked files. |
omz_hist_stamps |
mm/dd/yyyy |
Format for history stamps. |
omz_zsh_custom |
$ZSH/custom |
Custom scripts location. |
omz_plugins |
[] |
List of Oh My Zsh plugins to enable. |
Role Task Files
main.yml
: Task Coordination
This file organizes the tasks to be performed.
zsh.yml
: Zsh Setup
This task installs Zsh and sets it as the default shell for a user.
Variables Used
omz_user
oh-my-zsh-install.yml
: Oh My Zsh Installation
This task clones the Oh My Zsh repository into each specified user's directory and sets the right permissions.
Variables Used
omz_user
omz_install_directory
omz_git_repository
omz_install_path
oh-my-zsh-zshrc.yml
: Oh My Zsh Configuration
This task creates a .zshrc
file for the user with global settings for various Oh My Zsh options. It can back up any existing .zshrc
file if needed.
This runs only when omz_zshrc_create
is true.
Variables Used
omz_user
omz_zshrc_template
omz_zshrc_backup
zsh-zshrc.yml
: Final Zsh Configuration
This task adds specific lines to an existing .zshrc
file, useful for changing settings without starting from scratch.
This runs only when omz_zshrc_create
is false.
Variables Used
omz_user
omz_zshrc_backup
Sample Playbook
---
- name: Playbook
hosts: all
become: true
vars:
omz_install_zsh: true
users:
- name: "lorem"
group: "lorem"
settings: ""
- name: "ipsum"
group: "ipsum"
settings: |
export PATH="/usr/local/sbin:$path"
alias l="ls -AF"
tasks:
- name: Run ansible-role-oh-my-zsh.
include_role:
name: "ansible-role-oh-my-zsh"
vars:
omz_user: "{{ item }}"
# Create `.zshrc` for user 'lorem'; settings for user 'ipsum' will be added to `.zshrc`.
omz_zshrc_create: "{{ (item.name == 'lorem') | ternary(true, false) }}"
omz_plugins:
- "autojump"
- "git"
with_items: "{{ users }}"
Installs and configures oh-my-zsh for one or more users on Fedora, macOS, or Ubuntu.
ansible-galaxy install ctorgalson.oh-my-zsh