def file(
    state, host, name,
    present=True, user=None, group=None, mode=None, touch=False,
):
    '''
    Add/remove/update files.

    + name: name/path of the remote file
    + present: whether the file should exist
    + user: user to own the files
    + group: group to own the files
    + mode: permissions of the files as an integer, eg: 755
    + touch: whether to touch the file
    '''

    mode = ensure_mode_int(mode)
    info = host.fact.file(name)

    # Not a file?!
    if info is False:
        raise OperationError('{0} exists and is not a file'.format(name))

    # Doesn't exist & we want it
    if info is None and present:
        yield 'touch {0}'.format(name)

        if mode:
            yield chmod(name, mode)
        if user or group:
            yield chown(name, user, group)

    # It exists and we don't want it
    elif info and not present:
        yield 'rm -f {0}'.format(name)

    # It exists & we want to ensure its state
    elif info and present:
        if touch:
            yield 'touch {0}'.format(name)

        # Check mode
        if mode and info['mode'] != mode:
            yield chmod(name, mode)

        # Check user/group
        if (user and info['user'] != user) or (group and info['group'] != group):
            yield chown(name, user, group)
def file ( state , host , name , present = True , user = None , group = None , mode = None , touch = False , ) : mode = ensure_mode_int ( mode ) info = host . fact . file ( name ) if info is False : raise OperationError ( '{0} exists and is not a file' . format ( name ) ) if info is None and present : yield 'touch {0}' . format ( name ) if mode : yield chmod ( name , mode ) if user or group : yield chown ( name , user , group ) elif info and not present : yield 'rm -f {0}' . format ( name ) elif info and present : if touch : yield 'touch {0}' . format ( name ) if mode and info [ 'mode' ] != mode : yield chmod ( name , mode ) if ( user and info [ 'user' ] != user ) or ( group and info [ 'group' ] != group ) : yield chown ( name , user , group )
Add/remove/update files.

    + name: name/path of the remote file
    + present: whether the file should exist
    + user: user to own the files
    + group: group to own the files
    + mode: permissions of the files as an integer, eg: 755
    + touch: whether to touch the file