.. versionadded:: 0.17.0

    Verify that a device is not mounted

    name
        The path to the location where the device is to be unmounted from

    device
        The device to be unmounted.  This is optional because the device could
        be mounted in multiple places.

        .. versionadded:: 2015.5.0

    config
        Set an alternative location for the fstab, Default is ``/etc/fstab``

    persist
        Set if the mount should be purged from the fstab, Default is ``False``

    user
        The user to own the mount; this defaults to the user salt is
        running as on the minion

def unmounted(name,
              device=None,
              config='/etc/fstab',
              persist=False,
              user=None,
              **kwargs):
    '''
    .. versionadded:: 0.17.0

    Verify that a device is not mounted

    name
        The path to the location where the device is to be unmounted from

    device
        The device to be unmounted.  This is optional because the device could
        be mounted in multiple places.

        .. versionadded:: 2015.5.0

    config
        Set an alternative location for the fstab, Default is ``/etc/fstab``

    persist
        Set if the mount should be purged from the fstab, Default is ``False``

    user
        The user to own the mount; this defaults to the user salt is
        running as on the minion
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    update_mount_cache = False

    if not name:
        ret['result'] = False
        ret['comment'] = 'Must provide name to mount.unmounted'
        return ret

    # Get the active data
    active = __salt__['mount.active'](extended=True)
    if name not in active:
        # Nothing to unmount
        ret['comment'] = 'Target was already unmounted'
    if name in active:
        # The mount is present! Unmount it
        if __opts__['test']:
            ret['result'] = None
            ret['comment'] = ('Mount point {0} is mounted but should not '
                              'be').format(name)
            return ret
        if device:
            out = __salt__['mount.umount'](name, device, user=user)
            update_mount_cache = True
        else:
            out = __salt__['mount.umount'](name, user=user)
            update_mount_cache = True
        if isinstance(out, string_types):
            # Failed to umount, the state has failed!
            ret['comment'] = out
            ret['result'] = False
        elif out is True:
            # umount worked!
            ret['comment'] = 'Target was successfully unmounted'
            ret['changes']['umount'] = True
        else:
            ret['comment'] = 'Execute set to False, Target was not unmounted'
            ret['result'] = True

    if update_mount_cache:
        cache_result = __salt__['mount.delete_mount_cache'](name)

    if persist:
        device_key_name = 'device'
        # Override default for Mac OS
        if __grains__['os'] in ['MacOS', 'Darwin'] and config == '/etc/fstab':
            config = "/etc/auto_salt"
            fstab_data = __salt__['mount.automaster'](config)
        elif 'AIX' in __grains__['os']:
            device_key_name = 'dev'
            if config == '/etc/fstab':
                config = "/etc/filesystems"
            fstab_data = __salt__['mount.filesystems'](config)
        elif 'Solaris' in __grains__['os']:
            if config == '/etc/fstab':
                config = '/etc/vfstab'
            fstab_data = __salt__['mount.vfstab'](config)
        else:
            fstab_data = __salt__['mount.fstab'](config)

        if name not in fstab_data:
            ret['comment'] += '. fstab entry not found'
        else:
            if device:
                if fstab_data[name][device_key_name] != device:
                    ret['comment'] += '. fstab entry for device {0} not found'.format(device)
                    return ret
            if __opts__['test']:
                ret['result'] = None
                ret['comment'] = ('Mount point {0} is unmounted but needs to '
                                  'be purged from {1} to be made '
                                  'persistent').format(name, config)
                return ret
            else:
                if __grains__['os'] in ['MacOS', 'Darwin']:
                    out = __salt__['mount.rm_automaster'](name, device, config)
                elif 'AIX' in __grains__['os']:
                    out = __salt__['mount.rm_filesystems'](name, device, config)
                elif 'Solaris' in __grains__['os']:
                    out = __salt__['mount.rm_vfstab'](name, device, config)
                else:
                    out = __salt__['mount.rm_fstab'](name, device, config)
                if out is not True:
                    ret['result'] = False
                    ret['comment'] += '. Failed to persist purge'
                else:
                    ret['comment'] += '. Removed target from fstab'
                    ret['changes']['persist'] = 'purged'

    return ret