@ -30,6 +30,7 @@ import base64
import sys
import shlex
import pipes
import re
import ansible . constants as C
import ansible . inventory
@ -128,7 +129,8 @@ class Runner(object):
check = False , # don't make any changes, just try to probe for potential changes
diff = False , # whether to show diffs for template files that change
environment = None , # environment variables (as dict) to use inside the command
complex_args = None # structured data in addition to module_args, must be a dict
complex_args = None , # structured data in addition to module_args, must be a dict
error_on_undefined_vars = C . DEFAULT_UNDEFINED_VAR_BEHAVIOR # ex. False
) :
if not complex_args :
@ -163,6 +165,7 @@ class Runner(object):
self . is_playbook = is_playbook
self . environment = environment
self . complex_args = complex_args
self . error_on_undefined_vars = error_on_undefined_vars
self . callbacks . runner = self
@ -435,11 +438,11 @@ class Runner(object):
raise errors . AnsibleError ( " args must be a dictionary, received %s " % complex_args )
result = self . _executor_internal_inner (
host ,
self . module_name ,
self . module_args ,
inject ,
port ,
host ,
self . module_name ,
self . module_args ,
inject ,
port ,
complex_args = complex_args
)
results . append ( result . result )
@ -626,7 +629,7 @@ class Runner(object):
path = pipes . quote ( path )
# The following test needs to be SH-compliant. BASH-isms will
# not work if /bin/sh points to a non-BASH shell.
test = " rc=0; [ -r \" %s \" ] || rc=2; [ -f \" %s \" ] || rc=1; [ -d \" %s \" ] && rc=3 " % ( ( path , ) * 3 )
test = " rc=0; [ -r \" %s \" ] || rc=2; [ -f \" %s \" ] || rc=1; [ -d \" %s \" ] && rc=3 " % ( ( path , ) * 3 )
md5s = [
" (/usr/bin/md5sum %s 2>/dev/null) " % path , # Linux
" (/sbin/md5sum -q %s 2>/dev/null) " % path , # ?
@ -673,8 +676,16 @@ class Runner(object):
# *****************************************************
def _contains_undefined_vars ( self , module_args ) :
''' return true if there are undefined variables '''
return ' {{ ' in module_args
def _copy_module ( self , conn , tmp , module_name , module_args , inject , complex_args = None ) :
''' transfer a module over SFTP, does not run it '''
if self . error_on_undefined_vars and self . _contains_undefined_vars ( module_args ) :
vars = re . findall ( r ' {{ (.*?)}} ' , module_args )
raise errors . AnsibleUndefinedVariable ( " Undefined variables: %s " %
' , ' . join ( vars ) )
# FIXME if complex args is none, set to {}