Special shell for special users on special host %)

Hello!
I find some issue and cant resolve it by myself.
My scenario:
3 users, 4 hosts
I add information about users in file vars/all (like login, uid, comment, group and password) and deploy users via role with variable (user logins) into all hosts

==========================hosts file=============
[group1]
serv1
[group2]
serv2
serv3
==================playbook=================

  • hosts: all
    vars:
    ssh_users:

  • “{{user1}}”
    roles:

  • users_add

  • hosts: group1
    vars:
    ssh_users:

  • “{{user2}}”

  • “{{user3}}”
    roles:

  • users_add

  • hosts: group2
    vars:
    ssh_users:

  • “{{user2}}”
    roles:

  • users_add

============= vars/all====================
user1:

  • { user: ‘user1’, uid: ‘11111’ }
    user2:
  • { user: ‘user2’, uid: ‘11112’ }
    user3:
  • { user: ‘user3’, uid: ‘11113’ }
    ============= role file =====================
  • name: Add ssh user
    user: name={{ item.user }} uid= {{ item.uid}}
    with_items: “ssh_users”

Petr,

I’ll augment your example with this behavior. Since you’re adding “user 1” by it’s own when matching all hosts; it kind of takes care of the requirement to avoid changing user 1’s shell. See below;

`

Hi folks,

When posting YAML it greatly helps if things are well formatted.

If you are posting in an mail editor that doesn’t allow proper whitespace, I’d recommend using something like gist.github.com.

Otherwise it’s pretty hard to read the above.

Thanks!

Hi, Bruce!
Yes, it is exactly what i am looking for! Working like charm!

Michael, i will use this source in next time, thanks

Thanks so much!