I have the following task
- name: Create users
user:
uid: "{{ item.uid }}"
name: "{{ item.username }}"
comment: "{{ item.comment }}"
shell: /bin/bash
groups: "{{ item.groups }}"
with_items: users
users
contains all the users working in the company and I want to create all of them on the samba servers. But there are also 3 admins and I only want to create them in the other servers that is not in the samba group.
I can create the admin users with the above if I add
when: item.username in admin_users
, but that will do it for all users and I want the default for new servers to be to only create the admin_users, but if the server is in the samba group, create all the users.
Will there be an easy way to do this? I'm thinking of splitting users into two group and create admin_user and other_users by running two tasks, but I would like to know if there is a DRY solution to this problem.
playbook.yml
hosts
sample session: