Get user details

31 views
Skip to first unread message

Ravikumar Wagh

unread,
Nov 2, 2017, 7:09:14 AM11/2/17
to Ansible Project
Is there any way to get available users in system or an spcific user details.

Soniya panwar

unread,
Nov 7, 2017, 3:16:49 AM11/7/17
to Ansible Project
hello,

Yes, you can get available users or user details in system by using ansible playbooks. For this you need to use the command / win_command module. 
"The command module takes the command name followed by a list of space-delimited arguments and executes the given command on all selected nodes."

If  you are trying to retrieve user or user details on a linux system, you may use below playbooks: 

1. To get available users in system 

   - name: get available users in system
     command: cut -d: -f1 /etc/passwd
     register: AvailableUsers

  - debug: msg="{{ AvailableUsers.stdout }}"

2. To get a spcific user details.

   - name: get specific user details in system
     command: id username
     register: SpecificUserDetails

- debug: msg="{{ SpecificUserDetails.stdout }}"


If  you are trying to retrieve user or user details on a windows system, you may use below playbooks: 

1. To get available users in system 

   - name: get available users in system
     win_command: net user 
     register: AvailableUsers

  - debug: msg="{{ AvailableUsers.stdout }}"

2. To get a spcific user details.

   - name: get specific user details in system
     win_command: net user  username
     register: SpecificUserDetails

- debug: msg="{{ SpecificUserDetails.stdout }}"

Thanks
Soniya
Reply all
Reply to author
Forward
0 new messages