# Host\_vars for users

**URL:** <https://forum.ansible.com/t/host-vars-for-users/38942>\
**Category:** Get Help\
**Created:** [December 6, 2024, 7:36am UTC](https://forum.ansible.com/t/host-vars-for-users/38942 "2024-12-06T07:36:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_shorty](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_shorty](https://forum.ansible.com/u/_shorty)\
**Post date:** [December 6, 2024, 7:36am UTC](https://forum.ansible.com/t/host-vars-for-users/38942/1 "2024-12-06T07:36:14Z")

</div>

Hi,

I’m really new to ansible and I’m still learning but I’m stuck and need your help.  
I want to use host\_vars for a list of users to deploy them to a host.

Let’s say we have three users (with it ssh keys) and 2 machines

> Joe, Jack and John

> srv1 and srv2

Now I’ld like to realize that on srv1 only joe and jack will be deployed and on srv2 all three of them should be deployed. But all users should be maintained in one user.yml file to keep maintenance on usernames and ssh key’s low.

How do I need to declare that in the host\_vars file? Can I reference there to my users.yml file? If yes how?

\_Shorty

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [December 6, 2024, 4:38pm UTC](https://forum.ansible.com/t/host-vars-for-users/38942/2 "2024-12-06T16:38:01Z")

</div>

Lots of ways to slice this up, but you either have to reference (directly or indirectly) the hosts from the users, or the users from the hosts.

I might create my one `users.yml` as `group_vars/all/users.yml` so the user data would be available to all hosts. Then the data might look like this:

```yaml
---
# group_vars/all/users.yml
project_host_users:
  - name: Joe Jones
    username: joe
    uid: 1345
    gid: 1345
    pub_key: "........"
    host_groups: # zero or more host groups
      - web_dev
      - web_tst
    hosts: [] # zero or more hosts
  - name: Jack Spratt
    username: jack
    uid: 1346
    gid: 1346
    pub_key: "........"
    host_groups: [] # zero or more host groups
    hosts: # zero or more hosts
      - srv1
      - srv2

```

Your role that deploys users onto hosts can filter out the ones appropriate for each host.

There are lots of other ways you could do it. It’s just a matter of which one you’re more comfortable maintaining.
