コード例 #1
0
ファイル: template.py プロジェクト: ferhaty/ansible
 def __getitem__(self, varname):
     from ansible.runner import HostVars
     if varname not in self.vars:
         for i in self.extras:
             if varname in i:
                 return i[varname]
         if varname in self.globals:
             return self.globals[varname]
         else:
             raise KeyError("undefined variable: %s" % varname)
     var = self.vars[varname]
     # HostVars is special, return it as-is, as is the special variable
     # 'vars', which contains the vars structure
     var = to_unicode(var, nonstring="passthru")
     if isinstance(var, dict) and varname == "vars" or isinstance(var, HostVars):
         return var
     else:
         return template(self.basedir, var, self.vars, fail_on_undefined=self.fail_on_undefined)
コード例 #2
0
 def __getitem__(self, varname):
     from ansible.runner import HostVars
     if varname not in self.vars:
         for i in self.extras:
             if varname in i:
                 return i[varname]
         if varname in self.globals:
             return self.globals[varname]
         else:
             raise KeyError("undefined variable: %s" % varname)
     var = self.vars[varname]
     # HostVars is special, return it as-is, as is the special variable
     # 'vars', which contains the vars structure
     var = to_unicode(var, nonstring="passthru")
     if isinstance(var, dict) and varname == "vars" or isinstance(var, HostVars):
         return var
     else:
         return template(self.basedir, var, self.vars, fail_on_undefined=self.fail_on_undefined)