append users to another group

14 views
Skip to first unread message

Marc Roelofs

unread,
May 25, 2016, 10:22:04 AM5/25/16
to Ansible Project
I am trying to figure out how to generate a list of users on a remote machine who are currently already a member of group A , and append them all to group B 
Is this possible ? 

Could not find a way to lookup existing users that are already a member of a group . I would like to be able to do this on different machines which have different users available , so creating a  list of users on my ansible management station and using it as input  is not an option 

Please advice 

Best Marc 

Matt Martz

unread,
May 25, 2016, 10:56:14 AM5/25/16
to ansible...@googlegroups.com
You can retrieve members of a group using the `getent` module:  http://docs.ansible.com/ansible/getent_module.html

Such as:

- getent: database=group split=':' key=sudo
  register: sudo_users

- debug: var=sudo_users.getent_group.sudo[3]

The output should be a comma separated list.  You could make this an actual python list using `sudo_users.getent_group.sudo[3].split(',')`


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/30cab7f7-39ca-4591-8024-2863d59a776d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages