User Modules:- To create the user
[ansible@ip-172-31-95-179 ~]$ vi user.yml
[ansible@ip-172-31-95-179 ~]$ cat user.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
user: name="mytestuser" state=present password="raj123456"
[ansible@ip-172-31-95-179 ~]$ vi user.yml
[ansible@ip-172-31-95-179 ~]$ cat user.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
user: name="mytestuser" state=present password="raj123456"
[ansible@ip-172-31-80-19 ~]$ ansible-playbook user.yml -i inventory.txt
now run the below command on client to check the created user
[root@ip-172-31-85-190 ~]# cd /home
[root@ip-172-31-85-190 home]# ls
--------------------------------------------------------------------------------------
To delete the user on client but not remove home directory
[ansible@ip-172-31-80-19 ~]$ cat user.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
user: name="mytestuser" state=absent
To check user are deleted on client
[root@ip-172-31-85-190 home]# cat /etc/passwd
To delete the user on client also remove the home directory of user
[ansible@ip-172-31-80-19 ~]$ cat user.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
user: name="mytestuser" state=absent remove=yes
[ansible@ip-172-31-80-19 ~]$
No comments:
Post a Comment