@ -19,7 +19,6 @@ __metaclass__ = type
import os
import os
from ansible import constants as C
from ansible . errors import AnsibleError
from ansible . errors import AnsibleError
from ansible . plugins . lookup import LookupBase
from ansible . plugins . lookup import LookupBase
from ansible . utils . unicode import to_unicode
from ansible . utils . unicode import to_unicode
@ -36,26 +35,25 @@ class LookupModule(LookupBase):
def run ( self , terms , variables , * * kwargs ) :
def run ( self , terms , variables , * * kwargs ) :
convert_data_p = kwargs . get ( ' convert_data ' , True )
convert_data_p = kwargs . get ( ' convert_data ' , True )
basedir = self . get_basedir ( variables )
ret = [ ]
ret = [ ]
for term in terms :
for term in terms :
display . debug ( " File lookup term: %s " % term )
display . debug ( " File lookup term: %s " % term )
lookupfile = self . _loader. path_dwim_relative ( basedir , ' templates ' , term )
lookupfile = self . find_file_in_search_path( variables , ' templates ' , term )
display . vvvv ( " File lookup using %s as file " % lookupfile )
display . vvvv ( " File lookup using %s as file " % lookupfile )
if lookupfile and os . path . exists ( lookupfile ) :
if lookupfile :
with open ( lookupfile , ' r ' ) as f :
with open ( lookupfile , ' r ' ) as f :
template_data = to_unicode ( f . read ( ) )
template_data = to_unicode ( f . read ( ) )
searchpath = [ self . _loader . _basedir , os . path . dirname ( lookupfile ) ]
# set jinja2 internal search path for includes
if ' role_path ' in variables :
if ' ansible_search_path ' in variables :
if C . DEFAULT_ROLES_PATH :
searchpath = variables [ ' ansible_search_path ' ]
searchpath [ : 0 ] = C . DEFAULT_ROLES_PATH
else :
searchpath . insert ( 1 , variables [ ' role_path ' ] )
searchpath = [ self . _loader . _basedir , os . path . dirname ( lookupfile ) ]
self . _templar . environment . loader . searchpath = searchpath
self . _templar . environment . loader . searchpath = searchpath
# do the templating
res = self . _templar . template ( template_data , preserve_trailing_newlines = True , convert_data = convert_data_p )
res = self . _templar . template ( template_data , preserve_trailing_newlines = True , convert_data = convert_data_p )
ret . append ( res )
ret . append ( res )
else :
else :