---
- name: Check for existence of ZSH.
  command: "which zsh"
  register: zsh_exists
  failed_when: "'{{ zsh_path }}' not in zsh_exists.stdout"
  always_run: true

- name: Ensure /etc/shells contains ZSH.
  lineinfile:
    dest: "/etc/shells"
    line: "{{ zsh_path }}"
  become: true

# We use `sudo ...` here instead of `become_user` because this way we can be
# assured of never being prompted for a user's password.
- name: Set ZSH shell as default for specified users.
  command: "chsh -s {{ zsh_path }} {{ item.user }}"
  with_items: "{{ zsh_users }}"
  when: "{{ zsh_users | length > 0 }}"
  become: true

---
- name: Check for existence of ZSH.
  command: "which zsh"
  register: zsh_exists
  failed_when: "'{{ zsh_path }}' not in zsh_exists.stdout"
  always_run: true

- name: Ensure /etc/shells contains ZSH.
  lineinfile:
    dest: "/etc/shells"
    line: "{{ zsh_path }}"
  become: true

- name: Set ZSH shell as default for specified users.
  user:
    name: "{{ item.user }}"
    shell: "{{ zsh_path }}"
  with_items: "{{ zsh_users }}"
  when: "{{ zsh_users | length > 0 }}"
  become: true

Replace `command` with `user` to change shells
Replace `command` with `user` to change shells

- gh-1