Closed Gictorbit closed 2 years ago
Hi @Gictorbit, unfortunately, loop
doesn't work with Ansible roles (only with tasks). Try the following instead:
- name: setup ohmyzsh for users
hosts: all
vars:
userlist:
- username: "viktor"
password: "viktor123"
become: yes
pre_tasks:
- name: build oh_my_zsh_users
set_fact:
oh_my_zsh_users: '{{ (oh_my_zsh_users | default([])) + [oh_my_zsh_user] }}'
vars:
oh_my_zsh_user:
username: '{{ item.username }}'
oh_my_zsh:
theme: gnzh
plugins:
- git
- zsh-syntax-highlighting
- zsh-autosuggestions
- docker
loop: '{{ userlist }}'
roles:
- role: gantsign.oh-my-zsh
users: '{{ oh_my_zsh_users }}'
Thank you, I also asked this question in stack overflow and solved this using include_role
you can check that from link below:
stack overflow
Yeah, include_role
also works, but the advantage of the approach I suggested is it allows you to sequence gantsign.oh-my-zsh
relative to other roles in the playbook in the normal way. With include_role
you're limited to before (pre_tasks
) or after (tasks
or post_tasks
) all the other roles in the playbook (unless you invoke them with include_role
as well).
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)