docs: def template_from_file(basedir, path, vars):
      ''' run a file through the templating engine '''
  
      from cirruscluster.ext.ansible import utils
      realpath = utils.path_dwim(basedir, path)
      loader=jinja2.FileSystemLoader([basedir,os.path.dirname(realpath)])
      environment = jinja2.Environment(loader=loader, trim_blocks=True)
      for filter_plugin in utils.plugins.filter_loader.all():
          filters = filter_plugin.filters()
          if not isinstance(filters, dict):
              raise errors.AnsibleError("FilterModule.filters should return a dict.")
          environment.filters.update(filters)
      try:
          data = codecs.open(realpath, encoding="utf8").read()
      except UnicodeDecodeError:
          raise errors.AnsibleError("unable to process as utf-8: %s" % realpath)
      except:
          raise errors.AnsibleError("unable to read %s" % realpath)
  
      # Get jinja env overrides from template
      if data.startswith(JINJA2_OVERRIDE):
          eol = data.find('\n')
          line = data[len(JINJA2_OVERRIDE):eol]
          data = data[eol+1:]
          for pair in line.split(','):
              (key,val) = pair.split(':')
              setattr(environment,key.strip(),val.strip())
  
      environment.template_class = J2Template
      t = environment.from_string(data)
      vars = vars.copy()
      try:
          template_uid = pwd.getpwuid(os.stat(realpath).st_uid).pw_name
      except:
          template_uid = os.stat(realpath).st_uid
      vars['template_host']   = os.uname()[1]
      vars['template_path']   = realpath
      vars['template_mtime']  = datetime.datetime.fromtimestamp(os.path.getmtime(realpath))
      vars['template_uid']    = template_uid
      vars['template_fullpath'] = os.path.abspath(realpath)
      vars['template_run_date'] = datetime.datetime.now()
  
      managed_default = C.DEFAULT_MANAGED_STR
      managed_str = managed_default.format(
                      host = vars['template_host'],
                      uid  = vars['template_uid'],
                      file = vars['template_path']
                      )
      vars['ansible_managed'] = time.strftime(managed_str,
                                  time.localtime(os.path.getmtime(realpath)))
  
      # This line performs deep Jinja2 magic that uses the _jinja2_vars object for vars
      # Ideally, this could use some API where setting shared=True and the object won't get
      # passed through dict(o), but I have not found that yet.
      res = jinja2.utils.concat(t.root_render_func(t.new_context(_jinja2_vars(basedir, vars, t.globals), shared=True)))
  
      if data.endswith('\n') and not res.endswith('\n'):
          res = res + '\n'
      return template(basedir, res, vars)