Add a user in the group.

    name
        Name of the group to modify

    username
        Username to add to the group

    root
        Directory to chroot into

    CLI Example:

    .. code-block:: bash

         salt '*' group.adduser foo bar

    Verifies if a valid username 'bar' as a member of an existing group 'foo',
    if not then adds it.

def adduser(name, username, root=None):
    '''
    Add a user in the group.

    name
        Name of the group to modify

    username
        Username to add to the group

    root
        Directory to chroot into

    CLI Example:

    .. code-block:: bash

         salt '*' group.adduser foo bar

    Verifies if a valid username 'bar' as a member of an existing group 'foo',
    if not then adds it.
    '''
    on_redhat_5 = __grains__.get('os_family') == 'RedHat' and __grains__.get('osmajorrelease') == '5'
    on_suse_11 = __grains__.get('os_family') == 'Suse' and __grains__.get('osmajorrelease') == '11'

    if __grains__['kernel'] == 'Linux':
        if on_redhat_5:
            cmd = ['gpasswd', '-a', username, name]
        elif on_suse_11:
            cmd = ['usermod', '-A', name, username]
        else:
            cmd = ['gpasswd', '--add', username, name]
        if root is not None:
            cmd.extend(('--root', root))
    else:
        cmd = ['usermod', '-G', name, username]
        if root is not None:
            cmd.extend(('-R', root))

    retcode = __salt__['cmd.retcode'](cmd, python_shell=False)

    return not retcode