Ensure beacon is configured with the included beacon data.

    Args:

        name (str):
            The name of the beacon ensure is configured.

        save (bool):
            ``True`` updates the beacons.conf. Default is ``False``.

    Returns:
        dict: A dictionary of information about the results of the state

    Example:

    .. code-block:: yaml

        ps_beacon:
          beacon.present:
            - name: ps
            - save: True
            - enable: False
            - services:
                salt-master: running
                apache2: stopped

def present(name,
            save=False,
            **kwargs):
    '''
    Ensure beacon is configured with the included beacon data.

    Args:

        name (str):
            The name of the beacon ensure is configured.

        save (bool):
            ``True`` updates the beacons.conf. Default is ``False``.

    Returns:
        dict: A dictionary of information about the results of the state

    Example:

    .. code-block:: yaml

        ps_beacon:
          beacon.present:
            - name: ps
            - save: True
            - enable: False
            - services:
                salt-master: running
                apache2: stopped
    '''
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': []}

    current_beacons = __salt__['beacons.list'](return_yaml=False, **kwargs)
    beacon_data = [{k: v} for k, v in six.iteritems(kwargs)]

    if name in current_beacons:

        if beacon_data == current_beacons[name]:
            ret['comment'].append('Job {0} in correct state'.format(name))
        else:
            if 'test' in __opts__ and __opts__['test']:
                kwargs['test'] = True
                result = __salt__['beacons.modify'](name, beacon_data, **kwargs)
                ret['comment'].append(result['comment'])
                ret['changes'] = result['changes']
            else:
                result = __salt__['beacons.modify'](name, beacon_data, **kwargs)
                if not result['result']:
                    ret['result'] = result['result']
                    ret['comment'] = result['comment']
                    return ret
                else:
                    if 'changes' in result:
                        ret['comment'].append('Modifying {0} in beacons'.format(name))
                        ret['changes'] = result['changes']
                    else:
                        ret['comment'].append(result['comment'])

    else:
        if 'test' in __opts__ and __opts__['test']:
            kwargs['test'] = True
            result = __salt__['beacons.add'](name, beacon_data, **kwargs)
            ret['comment'].append(result['comment'])
        else:
            result = __salt__['beacons.add'](name, beacon_data, **kwargs)
            if not result['result']:
                ret['result'] = result['result']
                ret['comment'] = result['comment']
                return ret
            else:
                ret['comment'].append('Adding {0} to beacons'.format(name))

    if save:
        __salt__['beacons.save'](**kwargs)
        ret['comment'].append('Beacon {0} saved'.format(name))

    ret['comment'] = '\n'.join(ret['comment'])
    return ret