append users to another group

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

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(',')