- name: Add ssh user
user: name={{ item.user }} shell={{ item.shell }} groups='admins'
with_items:
- $ssh_users
- hosts: appsIn next group (db for example) i use different values for ssh_users variable (like user1 and user3)
vars:
- ssh_users:
- $user1
- $user2
Hello!
I am newby in ansible world, but i like this tool and i try to use in my enviroment..
I have some question about user managment, and can't get solution :(
I have several projects (test, developer, production and same) I make separate folders for this projects with contain hosts, main.yml, ansible.cfg and roles folder... I try to add user accounts by adding special role- user_ssh, like this:- name: Add ssh user
user: name={{ item.user }} shell={{ item.shell }} groups='admins'
with_items:
- $ssh_users
Variable ssh_users i use in play-book and use it for any host grous. It looks like this:- hosts: appsIn next group (db for example) i use different values for ssh_users variable (like user1 and user3)
vars:
- ssh_users:
- $user1
- $user2
Thanks for you reply, Adam!
I think, this solution is working like charm, but main reason for defined users like variables - is keeping all information in separate file. It is more simple for managing information and apply changes...
For example, if i have 10 host groups and 40 users, and changing some information or add field for user - i need to change each entry in my playbook (or multiple playbooks). If i use separate file - i need to change only this file :)
user1:- { user: 'user1', shell: '/bin/sh' }
how i can change shell value in special host group to /bin/nologin for example? And keep it default value for other groups?...
Solved by myself.
Use trick with
shell={{ variable | default('/bin/sh') }} value.
Thanks a lot for help!