Code Monkey home page Code Monkey logo

ansible-role-oh-my-zsh's Introduction

Ansible Role: Oh My Zsh

Tests Ansible Galaxy License

Role to download, install and configure Oh-My-Zsh.

👎 Deprecation Notice 👎

This role is no longer maintained.

Requirements

  • Ansible >= 5 (Ansible Core >= 2.12)

  • Linux Distribution

    • Debian Family

      • Debian

        • Stretch (9)
        • Buster (10)
        • Bullseye (11)
      • Ubuntu

        • Bionic (18.04)
        • Focal (20.04)
    • RedHat Family

      • Rocky Linux

        • 8
      • Fedora

        • 35
    • SUSE Family

      • openSUSE

        • 15.3
    • Note: other versions are likely to work but have not been tested.

Role Variables

The following variables will change the behavior of this role (default values are shown below):

# Default theme
oh_my_zsh_theme: robbyrussell

# Default plugins
oh_my_zsh_plugins:
  - git

# Whether to install by default for all specified users.
# May be overridden by `oh_my_zsh: install:` under each user.
oh_my_zsh_install: true

# Default update mode for Oh-My-Zsh
# accepted values are:
# disabled (default)
# auto
# reminder
oh_my_zsh_update_mode: disabled

# Default update frequency in days. When the update mode is set to a value other
# than "disabled", this is the frequency (in days) to check for a new version.
# The value 0 will check every time a new shell session starts.
oh_my_zsh_update_frequency: 13

# Whether to write the ~/.zshrc file
# May be overridden by `oh_my_zsh: write_zshrc:` under each user.
oh_my_zsh_write_zshrc: true

# User configuration
# Important: oh-my-zsh is installed per user so you need to specify the users to install it for.
users:
  - username: example1
    oh_my_zsh:
      theme: robbyrussell
      plugins:
        - git
      update_mode: reminder
      update_frequency: 3
      write_zshrc: false
  - username: example2
    oh_my_zsh:
      theme: robbyrussell
      plugins:
        - git
        - mvn
      update_mode: auto
      update_frequency: 10
  - username: example3
    oh_my_zsh:
      install: false

Example Playbook

- hosts: servers
  roles:
    - role: gantsign.oh-my-zsh
      users:
        - username: example

More Roles From GantSign

You can find more roles from GantSign on Ansible Galaxy.

Development & Testing

This project uses Molecule to aid in the development and testing; the role is unit tested using Testinfra and pytest.

To develop or test you'll need to have installed the following:

Because the above can be tricky to install, this project includes Molecule Wrapper. Molecule Wrapper is a shell script that installs Molecule and it's dependencies (apart from Linux) and then executes Molecule with the command you pass it.

To test this role using Molecule Wrapper run the following command from the project root:

./moleculew test

Note: some of the dependencies need sudo permission to install.

License

MIT

Author Information

John Freeman

GantSign Ltd. Company No. 06109112 (registered in England)

ansible-role-oh-my-zsh's People

Contributors

alorence avatar dependabot[bot] avatar freemanjp avatar imp1sh avatar ipumpkin17 avatar roib20 avatar segfault16 avatar yardbirdsax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ansible-role-oh-my-zsh's Issues

Install custom themes and plugins

Specify custom themes in a 'themes' list and custom plugins in a 'plugins' list, each item having a 'name' and 'source' identifying its Git repo. Install the custom theme if a user has it named as their 'theme'. Install custom plugins if they are listed by name in a user's plugins list. I will have a PR ready shortly to address these features.

chmod: invalid mode

Hi 👋

I'm trying to run this role against a Ubuntu 22.04.4 LTS instance:

  roles:
    - role: gantsign.oh-my-zsh
      become: true
      tags:
        - shell_setup
      users:
        - username: nwon
          oh_my_zsh:
            theme: maran
            plugins:
              - git

Getting this error:

TASK [gantsign.oh-my-zsh : write .zshrc for users] ****************************************************************************
fatal: [resolvio-testing-new]: FAILED! => {"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chmod: invalid mode: ‘A+user:nwon:rx:allow’\nTry 'chmod --help' for more information.\n}). For information on working around this, see https://docs.ansible.com/ansible-core/2.16/playbook_guide/playbooks_privilege_escalation.html#risks-of-becoming-an-unprivileged-user"}

… where I think the interesting bit is:

chmod: invalid mode: ‘A+user:nwon:rx:allow’

FWIW, chmod --version yields chmod (GNU coreutils) 8.32. But the syntax looks pretty odd, so I don't think it's a version problem.

Do you have any idea what's going on here? Thanks a lot for any insights 🙏

Customising .zshrc

Thank you for this role, really nice and easy to use. I did try the antigen one but I'm not familiar with it just yet and it failed on macOS which is what I'm targetting mainly.

So I would like to add custom content to the .zshrc file but at the moment the jinja file doesn't support adding custom snippets. I can of course override in subsequent plays / roles but it doesn't feel very ansible like to do that.

I've got two options in my head and which would be best based on your experience:

  1. A variable to enable custom content and embed added content within that and append at the end of the .zshrc file.
# oh_my_zsh_zshrc_custom: ""
oh_my_zsh_zshrc_custom: |
  <insert script content here>

Eg. append at end of current template:

# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

{{ oh_my_zsh_zshrc_custom }}
  1. Allow user to supply own jinja template as an input
# oh_my_zsh_zshrc_custom_template: ""
oh_my_zsh_zshrc_custom_template: "{{ playbook_dir}}/templates/my_zshrc.j2"
  1. Maybe I'm missing the point and should be providing custom config in another location that will automatically get included?

Happy to do a PR if you think either of those options would be useful?

[EDIT] - Just seen this: #89

Also I realised that adding scripts to the ~/.oh-my-zsh/custom directory get included by default.
I was able to configure another role to output it's zsh config to a file there and it works.

Unable to write .zshrc while connected with unprivilegied user

Hi,

I usually perform all administrative tasks on my servers with a user different from "root". Unfortunately, in such case, it is impossible to perform some tasks as another user using Ansible privilege escalation.

The task write .zshrc for users will fail if it is executed for any user when connected as unprivilegied user:

TASK [gantsign.oh-my-zsh : write .zshrc for users] **************************************************
fatal: [ec2-**-***-***-***.eu-west-3.compute.amazonaws.com]: FAILED! => {}

MSG:

Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership of '/var/tmp/ansible-tmp-1569230087.9570866-96215917740751/': Operation not permitted
chown: changing ownership of '/var/tmp/ansible-tmp-1569230087.9570866-96215917740751/source': Operation not permitted
}). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user

with playbook

- hosts: all
  remote_user: my_admin_user
  vars:
    users:
    - username: dummy
      oh_my_zsh:
        theme: sporty_256
        plugins:
          - git
          - themes
  roles:
    - gantsign.oh-my-zsh

The error came from the task:

- name: write .zshrc for users
  become: yes
  become_user: '{{ item.username }}'
  template:
    src: zshrc.j2
    dest: '~{{ item.username }}/.zshrc'
    backup: yes
    mode: 'u=rw,go=r'
  with_items: '{{ users }}'

In Ansible docs, the suggested workarounds are:

  1. Use pipelining (works for all python modules but copy, fetch, template)
  2. Install POSIX.1e filesystem acl support on the managed host
  3. Don’t perform an action on the remote machine by becoming an unprivileged user

I have enabled pipelining (1) in ansible.cfg, to ensure most of the tasks works well (cloning the repository in ~dummy/.oh-my-zsh can be done by user my_admin_user). But since the last task use template module to write .zshrc, it fails if remote_user is not root.
I don't know how to do the (2)
Obviously, the (3) should be in your hands...

I wanted to open a Pull Request, modifying the task and using owner: '{{ item.username }}' instead of become_user: '{{ item.username }}', but I discovered this was the case before and has been changed in 02c7f16.
I understand that setting the owner of file is easy, but setting the corresponding primary group is challenging since it is not always the same "word".

I discovered there is some unix commands that can determine the primary group of a user, but I don't know which way to follow to resolve this issue.

What do you think ?

Prompt corrupted on boot console after install

The oh-my-zsh prompt uses symbols to show whether the previous command completed successfully. If the console is running in ISO-8859-1 (or any other non-UTF-8 charmap the symbol appears as a series of garbled characters.

Feature Request: Custom plugin installation

Hello what do you think about adding a way to install custom plugins ?

Generally it means:

  • clone a git repository in ~/.oh-my-zsh/custom/plugins
  • add an entry in the plugins list

`users` variable name too generic

Hi,

The users variable name is too generic as it can be used by different other roles.
Would you mind set it to a more specific name such as oh_my_zsh_users (I took it from others of your variables).
If you need me to do a PR, just let me know.

Regards,
Rudy

how to install ohmyzsh for users using loop?

hello, I just want to install oh-my-zsh for multiple users, so how can I do this?
Here is my Ansible playbook, but it throws an error (item not found)

- name: setup ohmyzsh for users
  hosts: all
  vars:
    userlist:
      - username: "viktor"
        password: "viktor123"
  become: yes
  roles:
    - role: gantsign.oh-my-zsh
      users:
        - username: "{{ item.username }}"
          oh_my_zsh:
            theme: gnzh
            plugins:
              - git
              - zsh-syntax-highlighting
              - zsh-autosuggestions
              - docker
      loop: "{{ userlist }}"

Add support for Fedora 25

It's likely the role already works on Fedora 25 but it should be added to the test matrix and added to the Ansible metadata.

Does not work as expected

Simple role with username only installs zsh, oh-my-zsh but user to be able to 'use' oh-my-zsh must type zsh in the terminal anyway In fact zsh is being set as default shell as expected but still themes and other stuff not loading automatically.

Os: Ubuntu 20 Focal LTS

Add support for OpenSUSE 42.2

It's likely the role already works on OpenSUSE 42.2 but it should be added to the test matrix and added to the Ansible metadata.

Error when installing role on OSX

When installing the role on OSX, the following error is received:

TASK [gantsign.oh-my-zsh : install dependencies] ****************************************************************************************************************************************************************************************
failed: [localhost] (item=git) => {"ansible_loop_var": "item", "changed": false, "item": "git", "msg": "Error: Running Homebrew as root is extremely dangerous and no longer supported.\nAs Homebrew does not drop privileges on installation you would be giving all\nbuild scripts full access to your system."}

Example configuration:

- role: gantsign.oh-my-zsh
      users:
        - username: "{{ user_name }}"
          plugins:
            - git
            - kube-ps1
            - vscode

Disabled updated

Hello!

Thank you for your work, I just have one question: I noticed that on the lines 30 and 31 of the templates/zshrc.j2 does not match with the current .zshrc file on the ohmyzsh repo, so I was wondering if it's ok to create a PR that enables the updates? Or if its better just to leave it as it's.

# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="true"

Kindest regards

Temp file issues

I have been using your role for quite a while, thanks!

I've ran into some troubles with the latest version. At first I thought it was Ansible 2.7 that caused it, but that is unrelated (I updated but Ansible and the role at the same time). In the end I downgrade to a previous version of the role and it worked fine again.

d888ed4

`TASK [gantsign.oh-my-zsh : clone oh-my-zsh for users] ************************************************************************************************************************************************************

ok: [x.lan] => (item={u'username': u'user', u'oh_my_zsh': {u'theme': u'robbyrussell', u'plugins': [u'git', u'docker', u'cpv', u'copydir', u'copyfile', u'zsh-syntax-highlighting']}})
[WARNING]: Module remote_tmp /home/docker/.ansible/tmp did not exist and was created with a mode of 0700, this may cause issues when running as another user. To avoid this, create the remote_tmp dir with the
correct permissions manually`

And later on:

`TASK [gantsign.oh-my-zsh : write .zshrc for users] ***************************************************************************************************************************************************************

changed: [x.lan] => (item={u'username': u'user', u'oh_my_zsh': {u'theme': u'robbyrussell', u'plugins': [u'git', u'docker', u'cpv', u'copydir', u'copyfile', u'zsh-syntax-highlighting']}})
fatal: [x.lan]: FAILED! => {"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership of '/var/tmp/ansible-tmp-1538996917.56-214497945895580/': Operation not permitted\nchown: changing ownership of '/var/tmp/ansible-tmp-1538996917.56-214497945895580/source': Operation not permitted\n}). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"}`

Missing acl package in oh_my_zsh_dependencies

If acl package is missing on system, ansible cant use setfacl, so trying chmod instead, that cant be used on another unpriveleged user with template module. More here. After installing that package on system, everything works fine

Add option to skip default .zshrc file creation

Hi,

I've been using your role and have had no issue, but I have a possible upgrade that could be made :

A boolean could be added to skip the default .zshrc file creation on install. Currently, when i rerun the playbook I have that uses this role this task is always marked as changed because I put my own custom .zshrc file later, and it would be nice if this small change could be added.

Kind regards,

David

Add support for CentOS 7

It's likely the role already works on CentOS 7 but they should be added to the test matrix and added to the Ansible metadata.

change in theme/plugins doesn't make it to .zshrc

Not sure if this is an expected behaviour, but after changing the gefault theme to "gnzh" and running the role/playbook again I can't see a change on my machines .zshrc...

Expected behaviour would be for it to be like this:

ZSH_THEME="XYZ"
changes to whatever I set in

    - role: gantsign.oh-my-zsh
      users:
        - username: '{{remoteuser}}'
          oh_my_zsh:
          theme: gnzh
          plugins:
            - git

sadly same is true if I add more plugins to the above shown array...

What should I do to make zsh-autosuggestions work?

Hi,
Here is my play book

- name: run role for each user
  include_role:
    name: gantsign.oh-my-zsh
  vars:
    users:
      - username: root
        oh_my_zsh:
          theme: gnzh
          plugins:
            - git
            - zsh-syntax-highlighting
            - zsh-autosuggestions
            - docker

The zsh-autosuggestions is in plugins but it does not autocomplete. Do I need to install something else beside the playbook?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.