---
- block: #red hat based distros
  - yum: 
      name: ['git', 'zsh', 'vim', 'wget']
      state: latest 
      update_cache: true
  when: ansible_os_family == "RedHat" and install_deps == true and update_only == false

- block: #debian based distros
  - apt: 
      name: ['git', 'zsh', 'vim', 'wget']
      state: latest 
      update_cache: true
  when: ansible_os_family == "Debian" and install_deps == true and update_only == false

- block: #alpine
  - apk:
      name: ['git', 'zsh', 'vim', 'wget', 'zsh-vcs', 'shadow']
      state: latest 
      update_cache: true
  when: ansible_os_family == "Alpine" and install_deps == true and update_only == false

- name: change default shell
  shell: '[[ ! $SHELL = "$(which zsh)" ]] && chsh -s "$(which zsh)" || true'
  async: 1
  poll: 0
  when: update_only == false

- name: remove oh-my-zsh if exists
  file: 
    path: /root/.oh-my-zsh/
    state: absent
  when: update_only == false

- name: updload zsh and vim config
  copy: 
    src: '{{item}}'
    dest: '{{dest_folder}}/.{{item}}'
  loop:
    - "vimrc"
    - "zshrc"

- name: Install zsh-syntax-highlighting
  shell: '[ ! -d "/usr/share/zsh-syntax-highlighting" ] && git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /usr/share/zsh-syntax-highlighting || true'
  when: update_only == false

- name: install oh-my-zsh if needed
  shell: 'sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc'
  when: update_only == false