@ -40,7 +40,7 @@ class AnsibleJ2Vars(Mapping):
To facilitate using builtin jinja2 things like range , globals are also handled here .
'''
def __init__ ( self , templar , globals , locals = None , * extras ):
def __init__ ( self , templar , globals , locals = None ):
'''
Initializes this object with a valid Templar ( ) object , as
well as several dictionaries of variables representing
@ -49,7 +49,6 @@ class AnsibleJ2Vars(Mapping):
self . _templar = templar
self . _globals = globals
self . _extras = extras
self . _locals = dict ( )
if isinstance ( locals , dict ) :
for key , val in iteritems ( locals ) :
@ -60,40 +59,33 @@ class AnsibleJ2Vars(Mapping):
self . _locals [ key ] = val
def __contains__ ( self , k ) :
if k in self . _templar . available_variables :
return True
if k in self . _locals :
return True
for i in self . _extras :
if k in i :
return True
if k in self . _templar . available_variables :
return True
if k in self . _globals :
return True
return False
def __iter__ ( self ) :
keys = set ( )
keys . update ( self . _templar . available_variables , self . _locals , self . _globals , * self . _extras )
keys . update ( self . _templar . available_variables , self . _locals , self . _globals )
return iter ( keys )
def __len__ ( self ) :
keys = set ( )
keys . update ( self . _templar . available_variables , self . _locals , self . _globals , * self . _extras )
keys . update ( self . _templar . available_variables , self . _locals , self . _globals )
return len ( keys )
def __getitem__ ( self , varname ) :
if varname not in self . _templar . available_variables :
if varname in self . _locals :
return self . _locals [ varname ]
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 )
variable = self . _templar . available_variables [ varname ]
if varname in self . _locals :
return self . _locals [ varname ]
if varname in self . _templar . available_variables :
variable = self . _templar . available_variables [ varname ]
elif varname in self . _globals :
return self . _globals [ varname ]
else :
raise KeyError ( " undefined variable: %s " % varname )
# HostVars is special, return it as-is, as is the special variable
# 'vars', which contains the vars structure
@ -127,4 +119,4 @@ class AnsibleJ2Vars(Mapping):
new_locals = self . _locals . copy ( )
new_locals . update ( locals )
return AnsibleJ2Vars ( self . _templar , self . _globals , locals = new_locals , * self . _extras )
return AnsibleJ2Vars ( self . _templar , self . _globals , locals = new_locals )