Set debconf selections from a file or a template

    .. code-block:: yaml

        <state_id>:
          debconf.set_file:
            - source: salt://pathto/pkg.selections

        <state_id>:
          debconf.set_file:
            - source: salt://pathto/pkg.selections?saltenv=myenvironment

        <state_id>:
          debconf.set_file:
            - source: salt://pathto/pkg.selections.jinja2
            - template: jinja
            - context:
                some_value: "false"

    source:
        The location of the file containing the package selections

    template
        If this setting is applied then the named templating engine will be
        used to render the package selections file, currently jinja, mako, and
        wempy are supported

    context
        Overrides default context variables passed to the template.

    defaults
        Default context passed to the template.

def set_file(name, source, template=None, context=None, defaults=None, **kwargs):
    '''
    Set debconf selections from a file or a template

    .. code-block:: yaml

        <state_id>:
          debconf.set_file:
            - source: salt://pathto/pkg.selections

        <state_id>:
          debconf.set_file:
            - source: salt://pathto/pkg.selections?saltenv=myenvironment

        <state_id>:
          debconf.set_file:
            - source: salt://pathto/pkg.selections.jinja2
            - template: jinja
            - context:
                some_value: "false"

    source:
        The location of the file containing the package selections

    template
        If this setting is applied then the named templating engine will be
        used to render the package selections file, currently jinja, mako, and
        wempy are supported

    context
        Overrides default context variables passed to the template.

    defaults
        Default context passed to the template.
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    if context is None:
        context = {}
    elif not isinstance(context, dict):
        ret['result'] = False
        ret['comment'] = 'Context must be formed as a dict'
        return ret

    if defaults is None:
        defaults = {}
    elif not isinstance(defaults, dict):
        ret['result'] = False
        ret['comment'] = 'Defaults must be formed as a dict'
        return ret

    if __opts__['test']:
        ret['result'] = None
        ret['comment'] = 'Debconf selections would have been set.'
        return ret

    if template:
        result = __salt__['debconf.set_template'](source, template, context, defaults, **kwargs)
    else:
        result = __salt__['debconf.set_file'](source, **kwargs)

    if result:
        ret['comment'] = 'Debconf selections were set.'
    else:
        ret['result'] = False
        ret['comment'] = 'Unable to set debconf selections from file.'

    return ret