Absent any user directory, there is no central authority on user names and IDs. (Maybe consider implementing directory auth at some point.)
Maintain a list of users with their UIDs in a variable, overriding at the group_vars or host_vars levels where necessary. Perhaps for a group abc
have vars file group_vars/abc/users.yml
:
---
users:
- uid: 1000
name: user
comment: "system Admin"
- uid: 1001
name: alice
comment: "Alice Alvin"
- uid: 1002
name: beth
comment: "Beth Biorn"
- uid: 1003
name: Chris
comment: "Chris Civers"
The task looks something like:
---
- name: create users
loop: "{{ users }}"
user:
name: "{{ item.name }}"
shell: /bin/bash
uid: "{{ item.uid }}"
comment: "{{ item.comment }}"
Several tasks remain to make this playbook fit for your purpose:
- Make a list of groups and create them in a similar way.
- Create overrides for the
users
var for groups that have conflicting GIDs or UIDs.