Ansible Tutorial : Ansible modules user & group |
In this topic we will learn about how to manage user and group using ansible modules, we use following ansible module for it.
- Ansible User Module
- Ansible Group Module
User Management
User Module : It is used for user management, create user, delete user and more
To help ansible user module
ansible-doc user
Ansible Tutorial - ansible-doc |
To Check password algorithm of Hosts, its must require to generate password and set password of user because plan text password does not support.
ansible 172.17.20.98 -m shell -a "authconfig --test" | grep password
Generate password :
python -c "from passlib.hash import sha512_crypt; import getpass; print sha512_crypt.using(rounds=5000).hash(getpass.getpass())"
$6$O.RWXg/0E73uMPKe$DF.CGkdD0F/z6Q9Pww31mGxKvgRlhIN3bLXh2U/TKWTbSdax47xxrXe5nehSkxS.rrLdKeJr8rbC5ZwhMJRuC0
Create a User : Using hash password string in ansible
ansible 172.17.20.98 -m user -a 'name=lokcar password=$6$O.RWXg/0E73uMPKe$DF.CGkdD0F/z6Q9Pww31mGxKvgRlhIN3bLXh2U/TKWTbSdax47xxrXe5nehSkxS.rrLdKeJr8rbC5ZwhMJRuC0 state=present'
To Create a user with define shell and home directory
ansible 172.17.20.98 -m user -a 'name=lokesh1 password=$6$n2em3sW/g7aKU6Ek$LgIJnIfmQkCqry3gOHpe8zNodK6yQ01SL2737eYtxjuJtbP0tRo5HRaOlf6.OzjpThGIyHf0kj4dv8f/yA9CN1 state=present home=/tmp/ shell=/usr/bin/lshell'
Ansible Tutorial - Create User with define Shell and Directory |
Change user primary group
ansible 172.17.20.98 -m user -a "name=lokesh group=tesy"
ansible 172.17.20.98 -m user -a "name=lokesh groups=lokesh"
Add user in multiple groups
ansible 172.17.20.98 -m user -a "name=lokesh append=yes groups=lokesh,apache,ftp"
Deleting a user
ansible 172.17.20.98 -m user -a "name=ans2 state=absent"
Ansible Tutorial - Delete Users |
Ansible Group Management :
To Create Group
ansible 172.17.20.98 -m group -a "name=ansible1"
Ansible Tutorial - Create Groups |
Delete group
ansible 172.17.20.98 -m group -a "name=ansible1 state=absent"
Thanks
End of this ansble ad-hoc command and ansible modules, we need your support so i request you to please comment, share and like this post
www.linuxtopic.com
Useful article
ReplyDelete