@ -45,40 +45,73 @@ class IncludeRole(Task):
# =================================================================================
# ATTRIBUTES
_name = FieldAttribute ( isa = ' string ' , default = None )
_tasks_from = FieldAttribute ( isa = ' string ' , default = None )
# private as this is a 'module options' vs a task property
_static = FieldAttribute ( isa = ' bool ' , default = None , private = True )
_private = FieldAttribute ( isa = ' bool ' , default = None , private = True )
# these should not be changeable?
_static = FieldAttribute ( isa = ' bool ' , default = False )
_private = FieldAttribute ( isa = ' bool ' , default = True )
def __init__ ( self , block = None , role = None , task_include = None ) :
@staticmethod
def load ( data , block = None , role = None , task_include = None , variable_manager = None , loader = None ) :
super ( IncludeRole , self ) . __init__ ( block = block , role = role , task_include = task_include )
r = IncludeRole ( ) . load_data ( data , variable_manager = variable_manager , loader = loader )
args = r . preprocess_data ( data ) . get ( ' args ' , dict ( ) )
self . _role_name = None
self . statically_loaded = False
self . _from_files = { }
self . _parent_role = role
ri = RoleInclude . load ( args . get ( ' name ' ) , play = block . _play , variable_manager = variable_manager , loader = loader )
ri . vars . update ( r . vars )
# build options for roles
from_files = { }
for key in [ ' tasks ' , ' vars ' , ' defaults ' ] :
from_key = key + ' _from '
if args . get ( from_key ) :
from_files [ key ] = basename ( args . get ( from_key ) )
def get_block_list ( self , play = None , variable_manager = None , loader = None ) :
# only need play passed in when dynamic
if play is None :
myplay = self . _parent . _play
else :
myplay = play
ri = RoleInclude . load ( self . _role_name , play = myplay , variable_manager = variable_manager , loader = loader )
ri . vars . update ( self . vars )
#ri._role_params.update(self.args) # jimi-c cant we avoid this?
#build role
actual_role = Role . load ( ri , block . _play , parent_role = role , from_files = from_files )
actual_role = Role . load ( ri , myplay, parent_role = self . _parent_role , from_files = self . _ from_files)
# compile role
blocks = actual_role . compile ( play = block. _ play)
blocks = actual_role . compile ( play = my play)
# set parent to ensure proper inheritance
for b in blocks :
b . _parent = block
b . _parent = self . _parent
# updated available handlers in play
block. _play . handlers = block . _ play. handlers + actual_role . get_handler_blocks ( play = block. _ play)
myplay. handlers = my play. handlers + actual_role . get_handler_blocks ( play = my play)
return blocks
@staticmethod
def load ( data , block = None , role = None , task_include = None , variable_manager = None , loader = None ) :
ir = IncludeRole ( block , role , task_include = task_include ) . load_data ( data , variable_manager = variable_manager , loader = loader )
#TODO: use more automated list: for builtin in r.get_attributes(): #jimi-c: doing this to avoid using role_params and conflating include_role specific opts with other tasks
# set built in's
ir . _role_name = ir . args . get ( ' name ' )
for builtin in [ ' static ' , ' private ' ] :
if ir . args . get ( builtin ) :
setattr ( ir , builtin , ir . args . get ( builtin ) )
# build options for roles
for key in [ ' tasks ' , ' vars ' , ' defaults ' ] :
from_key = key + ' _from '
if ir . args . get ( from_key ) :
ir . _from_files [ key ] = basename ( ir . args . get ( from_key ) )
return ir . load_data ( data , variable_manager = variable_manager , loader = loader )
def copy ( self , exclude_parent = False , exclude_tasks = False ) :
new_me = super ( IncludeRole , self ) . copy ( exclude_parent = exclude_parent , exclude_tasks = exclude_tasks )
new_me . statically_loaded = self . statically_loaded
new_me . _role_name = self . _role_name
new_me . _from_files = self . _from_files . copy ( )
new_me . _parent_role = self . _parent_role
return new_me