How do I handle different machines needing different user accounts?

Hi,

Can’t find an answer to this.

The Ansible documents talk about “How do I handle different machines needing different user accounts or ports to log in with?”, and other things, but I can’t see how to address what we’re trying to do from the information and zillions of searches I’ve done on Google and this list.

I’m open to different ways of doing it, but ideally (I guess), I’d like to have a single file that lists all our hosts, and for each host, lists the login names (in addition to the “stock” login names) that should be on that machine. From that list, I’d like ansible to pull in the remaining user information to create the account (uid, primary gid, shell, comment, home directory, possibly a password), and then make sure the user’s account is on the machine.

I have gotten Ansible so that users common to all hosts are added. That works fine.

But how do I call the user module per host to have it add a list of additional users that are unique to that machine- ie. the users who have accounts on some machines and not others?

There is no grouping (eg. “web servers”) that this can be subsumed under in our environment.

This seems like a simple task but it isn’t obvious to me how to do it- at least not elegantly (especially in a way that’s dry).

Thanks in advance,

T N

i would write the users and their info in 1 file users.py:

allusers;
    username:
          uid: 123
          fullname: ....
   username2:
          uid: 321
          ....

and then for each host just list the users that have access, either in
host_vars/hostname.yml:

myusers:
- username
- username1

or inline in the ini file:

hotname myusers=[ 'username', 'username1']

then in the user creation task:

- users: uid={{allusers[item].uid}} ....
  with_items: "{{myusers}}"

There are other ways, but this seems to me easiest for you.