@ -29,7 +29,8 @@ class Play(object):
' hosts ' , ' name ' , ' vars ' , ' vars_prompt ' , ' vars_files ' ,
' hosts ' , ' name ' , ' vars ' , ' vars_prompt ' , ' vars_files ' ,
' handlers ' , ' remote_user ' , ' remote_port ' ,
' handlers ' , ' remote_user ' , ' remote_port ' ,
' sudo ' , ' sudo_user ' , ' transport ' , ' playbook ' ,
' sudo ' , ' sudo_user ' , ' transport ' , ' playbook ' ,
' tags ' , ' gather_facts ' , ' serial ' , ' _ds ' , ' _handlers ' , ' _tasks '
' tags ' , ' gather_facts ' , ' serial ' , ' _ds ' , ' _handlers ' , ' _tasks ' ,
' basedir '
]
]
# to catch typos and so forth -- these are userland names
# to catch typos and so forth -- these are userland names
@ -42,7 +43,7 @@ class Play(object):
# *************************************************
# *************************************************
def __init__ ( self , playbook , ds ):
def __init__ ( self , playbook , ds , basedir ):
''' constructor loads from a play datastructure '''
''' constructor loads from a play datastructure '''
for x in ds . keys ( ) :
for x in ds . keys ( ) :
@ -57,15 +58,15 @@ class Play(object):
elif isinstance ( hosts , list ) :
elif isinstance ( hosts , list ) :
hosts = ' ; ' . join ( hosts )
hosts = ' ; ' . join ( hosts )
hosts = utils . template ( hosts , playbook . extra_vars )
hosts = utils . template ( hosts , playbook . extra_vars )
self . _ds = ds
self . _ds = ds
self . playbook = playbook
self . playbook = playbook
self . basedir = basedir
self . hosts = hosts
self . hosts = hosts
self . name = ds . get ( ' name ' , self . hosts )
self . name = ds . get ( ' name ' , self . hosts )
self . vars = ds . get ( ' vars ' , { } )
self . vars = ds . get ( ' vars ' , { } )
self . vars_files = ds . get ( ' vars_files ' , [ ] )
self . vars_files = ds . get ( ' vars_files ' , [ ] )
self . vars_prompt = ds . get ( ' vars_prompt ' , { } )
self . vars_prompt = ds . get ( ' vars_prompt ' , { } )
self . vars = self . _get_vars ( self . playbook . basedir )
self . vars = self . _get_vars ( )
self . _tasks = ds . get ( ' tasks ' , [ ] )
self . _tasks = ds . get ( ' tasks ' , [ ] )
self . _handlers = ds . get ( ' handlers ' , [ ] )
self . _handlers = ds . get ( ' handlers ' , [ ] )
self . remote_user = utils . template ( ds . get ( ' user ' , self . playbook . remote_user ) , playbook . extra_vars )
self . remote_user = utils . template ( ds . get ( ' user ' , self . playbook . remote_user ) , playbook . extra_vars )
@ -107,7 +108,7 @@ class Play(object):
( k , v ) = t . split ( " = " , 1 )
( k , v ) = t . split ( " = " , 1 )
task_vars [ k ] = utils . template ( v , task_vars )
task_vars [ k ] = utils . template ( v , task_vars )
include_file = utils . template ( tokens [ 0 ] , task_vars )
include_file = utils . template ( tokens [ 0 ] , task_vars )
data = utils . parse_yaml_from_file ( utils . path_dwim ( self . playbook. basedir, include_file ) )
data = utils . parse_yaml_from_file ( utils . path_dwim ( self . basedir, include_file ) )
elif type ( x ) == dict :
elif type ( x ) == dict :
data = [ x ]
data = [ x ]
else :
else :
@ -135,7 +136,7 @@ class Play(object):
# *************************************************
# *************************************************
def _get_vars ( self , dirname ):
def _get_vars ( self ):
''' load the vars section from a play, accounting for all sorts of variable features
''' load the vars section from a play, accounting for all sorts of variable features
including loading from yaml files , prompting , and conditional includes of the first
including loading from yaml files , prompting , and conditional includes of the first
file found in a list . '''
file found in a list . '''
@ -264,7 +265,7 @@ class Play(object):
filename3 = filename2
filename3 = filename2
if host is not None :
if host is not None :
filename3 = utils . template ( filename2 , self . playbook . SETUP_CACHE [ host ] )
filename3 = utils . template ( filename2 , self . playbook . SETUP_CACHE [ host ] )
filename4 = utils . path_dwim ( self . playbook. basedir, filename3 )
filename4 = utils . path_dwim ( self . basedir, filename3 )
sequence . append ( filename4 )
sequence . append ( filename4 )
if os . path . exists ( filename4 ) :
if os . path . exists ( filename4 ) :
found = True
found = True
@ -297,7 +298,7 @@ class Play(object):
filename3 = filename2
filename3 = filename2
if host is not None :
if host is not None :
filename3 = utils . template ( filename2 , self . playbook . SETUP_CACHE [ host ] )
filename3 = utils . template ( filename2 , self . playbook . SETUP_CACHE [ host ] )
filename4 = utils . path_dwim ( self . playbook. basedir, filename3 )
filename4 = utils . path_dwim ( self . basedir, filename3 )
if self . _has_vars_in ( filename4 ) :
if self . _has_vars_in ( filename4 ) :
return
return
new_vars = utils . parse_yaml_from_file ( filename4 )
new_vars = utils . parse_yaml_from_file ( filename4 )