@operation
def group(
    state, host, name, present=True
):
    '''
    Manage system groups.

    + name: name of the group to ensure
    + present: whether the group should be present or not
    '''

    commands = []
    groups = host.fact.groups or []
    is_present = name in groups

    # Group exists but we don't want them?
    if not present and is_present:
        commands.append('groupdel {0}'.format(name))

    # Group doesn't exist and we want it?
    elif present and not is_present:
        commands.append('groupadd {0}'.format(name))

    return commands
dataset/ETHPy150Open Fizzadar/pyinfra/pyinfra/modules/server.py/group/original