@ -74,7 +74,7 @@ class Runner(object):
remote_user = C . DEFAULT_REMOTE_USER , remote_pass = C . DEFAULT_REMOTE_PASS ,
remote_user = C . DEFAULT_REMOTE_USER , remote_pass = C . DEFAULT_REMOTE_PASS ,
remote_port = C . DEFAULT_REMOTE_PORT , background = 0 , basedir = None , setup_cache = None ,
remote_port = C . DEFAULT_REMOTE_PORT , background = 0 , basedir = None , setup_cache = None ,
transport = ' paramiko ' , conditional = ' True ' , groups = { } , callbacks = None , verbose = False ,
transport = ' paramiko ' , conditional = ' True ' , groups = { } , callbacks = None , verbose = False ,
sudo = False ):
sudo = False , extra_vars = None ):
if setup_cache is None :
if setup_cache is None :
setup_cache = { }
setup_cache = { }
@ -101,6 +101,7 @@ class Runner(object):
self . forks = int ( forks )
self . forks = int ( forks )
self . pattern = pattern
self . pattern = pattern
self . module_args = module_args
self . module_args = module_args
self . extra_vars = extra_vars
self . timeout = timeout
self . timeout = timeout
self . verbose = verbose
self . verbose = verbose
self . remote_user = remote_user
self . remote_user = remote_user
@ -143,14 +144,17 @@ class Runner(object):
# *****************************************************
# *****************************************************
@classmethod
@classmethod
def parse_hosts_from_script ( cls , host_list ):
def parse_hosts_from_script ( cls , host_list , extra_vars ):
''' evaluate a script that returns list of hosts by groups '''
''' evaluate a script that returns list of hosts by groups '''
results = [ ]
results = [ ]
groups = dict ( ungrouped = [ ] )
groups = dict ( ungrouped = [ ] )
host_list = os . path . abspath ( host_list )
host_list = os . path . abspath ( host_list )
cls . _external_variable_script = host_list
cls . _external_variable_script = host_list
cmd = subprocess . Popen ( [ host_list ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE , shell = False )
cmd = [ host_list , ' --list ' ]
if extra_vars :
cmd . extend ( [ ' --extra-vars ' , extra_vars ] )
cmd = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE , shell = False )
out , err = cmd . communicate ( )
out , err = cmd . communicate ( )
try :
try :
groups = utils . json_loads ( out )
groups = utils . json_loads ( out )
@ -165,7 +169,7 @@ class Runner(object):
# *****************************************************
# *****************************************************
@classmethod
@classmethod
def parse_hosts ( cls , host_list , override_hosts = None ):
def parse_hosts ( cls , host_list , override_hosts = None , extra_vars = None ):
''' parse the host inventory file, returns (hosts, groups) '''
''' parse the host inventory file, returns (hosts, groups) '''
if override_hosts is not None :
if override_hosts is not None :
@ -183,7 +187,7 @@ class Runner(object):
if not os . access ( host_list , os . X_OK ) :
if not os . access ( host_list , os . X_OK ) :
return Runner . parse_hosts_from_regular_file ( host_list )
return Runner . parse_hosts_from_regular_file ( host_list )
else :
else :
return Runner . parse_hosts_from_script ( host_list )
return Runner . parse_hosts_from_script ( host_list , extra_vars )
# *****************************************************
# *****************************************************
@ -275,7 +279,12 @@ class Runner(object):
''' support per system variabes from external variable scripts, see web docs '''
''' support per system variabes from external variable scripts, see web docs '''
host = conn . host
host = conn . host
cmd = subprocess . Popen ( [ Runner . _external_variable_script , host ] ,
cmd = [ Runner . _external_variable_script , ' --host ' , host ]
if self . extra_vars :
cmd . extend ( [ ' --extra-vars ' , self . extra_vars ] )
cmd = subprocess . Popen ( cmd ,
stdout = subprocess . PIPE ,
stdout = subprocess . PIPE ,
stderr = subprocess . PIPE ,
stderr = subprocess . PIPE ,
shell = False
shell = False
@ -384,9 +393,13 @@ class Runner(object):
''' transfer & execute a module that is not ' copy ' or ' template ' '''
''' transfer & execute a module that is not ' copy ' or ' template ' '''
# shell and command are the same module
# shell and command are the same module
# FIXME: keep these args as strings as long as possible...
if module_name == ' shell ' :
if module_name == ' shell ' :
module_name = ' command '
module_name = ' command '
self . module_args . append ( " #USE_SHELL " )
if type ( self . module_args ) == list :
self . module_args . append ( " #USE_SHELL " )
else :
self . module_args + = " #USE_SHELL "
module = self . _transfer_module ( conn , tmp , module_name )
module = self . _transfer_module ( conn , tmp , module_name )
( result , executed ) = self . _execute_module ( conn , tmp , module , self . module_args )
( result , executed ) = self . _execute_module ( conn , tmp , module , self . module_args )
@ -406,7 +419,12 @@ class Runner(object):
module_args = self . module_args
module_args = self . module_args
if module_name == ' shell ' :
if module_name == ' shell ' :
module_name = ' command '
module_name = ' command '
module_args . append ( " #USE_SHELL " )
# FIXME: this will become cleaner once we keep args as a string
# throughout the app
if type ( module_args ) == list :
module_args . append ( " #USE_SHELL " )
else :
module_args + = " #USE_SHELL "
async = self . _transfer_module ( conn , tmp , ' async_wrapper ' )
async = self . _transfer_module ( conn , tmp , ' async_wrapper ' )
module = self . _transfer_module ( conn , tmp , module_name )
module = self . _transfer_module ( conn , tmp , module_name )