|
|
@ -34,6 +34,7 @@ import pipes
|
|
|
|
import ansible.constants as C
|
|
|
|
import ansible.constants as C
|
|
|
|
import ansible.inventory
|
|
|
|
import ansible.inventory
|
|
|
|
from ansible import utils
|
|
|
|
from ansible import utils
|
|
|
|
|
|
|
|
from ansible.utils import template
|
|
|
|
from ansible import errors
|
|
|
|
from ansible import errors
|
|
|
|
from ansible import module_common
|
|
|
|
from ansible import module_common
|
|
|
|
import poller
|
|
|
|
import poller
|
|
|
@ -62,7 +63,14 @@ def _executor_hook(job_queue, result_queue):
|
|
|
|
while not job_queue.empty():
|
|
|
|
while not job_queue.empty():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
host = job_queue.get(block=False)
|
|
|
|
host = job_queue.get(block=False)
|
|
|
|
result_queue.put(multiprocessing_runner._executor(host))
|
|
|
|
return_data = multiprocessing_runner._executor(host)
|
|
|
|
|
|
|
|
result_queue.put(return_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print "FLAGS=%s" % return_data.flags
|
|
|
|
|
|
|
|
if 'LEGACY_TEMPLATE_WARNING' in return_data.flags:
|
|
|
|
|
|
|
|
# pass data back up across the multiprocessing fork boundary
|
|
|
|
|
|
|
|
template.Flags.LEGACY_TEMPLATE_WARNING = True
|
|
|
|
|
|
|
|
|
|
|
|
except Queue.Empty:
|
|
|
|
except Queue.Empty:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
except:
|
|
|
@ -233,7 +241,7 @@ class Runner(object):
|
|
|
|
|
|
|
|
|
|
|
|
if not self.environment:
|
|
|
|
if not self.environment:
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
enviro = utils.template(self.basedir, self.environment, inject)
|
|
|
|
enviro = template.template(self.basedir, self.environment, inject)
|
|
|
|
if type(enviro) != dict:
|
|
|
|
if type(enviro) != dict:
|
|
|
|
raise errors.AnsibleError("environment must be a dictionary, received %s" % enviro)
|
|
|
|
raise errors.AnsibleError("environment must be a dictionary, received %s" % enviro)
|
|
|
|
result = ""
|
|
|
|
result = ""
|
|
|
@ -271,7 +279,7 @@ class Runner(object):
|
|
|
|
# do --check mode, so to be safe we will not run it.
|
|
|
|
# do --check mode, so to be safe we will not run it.
|
|
|
|
return ReturnData(conn=conn, result=dict(skippped=True, msg="cannot run check mode against old-style modules"))
|
|
|
|
return ReturnData(conn=conn, result=dict(skippped=True, msg="cannot run check mode against old-style modules"))
|
|
|
|
|
|
|
|
|
|
|
|
args = utils.template(self.basedir, args, inject)
|
|
|
|
args = template.template(self.basedir, args, inject)
|
|
|
|
argsfile = self._transfer_str(conn, tmp, 'arguments', args)
|
|
|
|
argsfile = self._transfer_str(conn, tmp, 'arguments', args)
|
|
|
|
if async_jid is None:
|
|
|
|
if async_jid is None:
|
|
|
|
cmd = "%s %s" % (remote_module_path, argsfile)
|
|
|
|
cmd = "%s %s" % (remote_module_path, argsfile)
|
|
|
@ -300,10 +308,20 @@ class Runner(object):
|
|
|
|
def _executor(self, host):
|
|
|
|
def _executor(self, host):
|
|
|
|
''' handler for multiprocessing library '''
|
|
|
|
''' handler for multiprocessing library '''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_flags():
|
|
|
|
|
|
|
|
# flags are a way of passing arbitrary event information
|
|
|
|
|
|
|
|
# back up the chain, since multiprocessing forks and doesn't
|
|
|
|
|
|
|
|
# allow state exchange
|
|
|
|
|
|
|
|
flags = []
|
|
|
|
|
|
|
|
if template.Flags.LEGACY_TEMPLATE_WARNING:
|
|
|
|
|
|
|
|
flags.append('LEGACY_TEMPLATE_WARNING')
|
|
|
|
|
|
|
|
return flags
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
exec_rc = self._executor_internal(host)
|
|
|
|
exec_rc = self._executor_internal(host)
|
|
|
|
if type(exec_rc) != ReturnData:
|
|
|
|
if type(exec_rc) != ReturnData:
|
|
|
|
raise Exception("unexpected return type: %s" % type(exec_rc))
|
|
|
|
raise Exception("unexpected return type: %s" % type(exec_rc))
|
|
|
|
|
|
|
|
exec_rc.flags = get_flags()
|
|
|
|
# redundant, right?
|
|
|
|
# redundant, right?
|
|
|
|
if not exec_rc.comm_ok:
|
|
|
|
if not exec_rc.comm_ok:
|
|
|
|
self.callbacks.on_unreachable(host, exec_rc.result)
|
|
|
|
self.callbacks.on_unreachable(host, exec_rc.result)
|
|
|
@ -311,11 +329,11 @@ class Runner(object):
|
|
|
|
except errors.AnsibleError, ae:
|
|
|
|
except errors.AnsibleError, ae:
|
|
|
|
msg = str(ae)
|
|
|
|
msg = str(ae)
|
|
|
|
self.callbacks.on_unreachable(host, msg)
|
|
|
|
self.callbacks.on_unreachable(host, msg)
|
|
|
|
return ReturnData(host=host, comm_ok=False, result=dict(failed=True, msg=msg))
|
|
|
|
return ReturnData(host=host, comm_ok=False, result=dict(failed=True, msg=msg), flags=get_flags())
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
msg = traceback.format_exc()
|
|
|
|
msg = traceback.format_exc()
|
|
|
|
self.callbacks.on_unreachable(host, msg)
|
|
|
|
self.callbacks.on_unreachable(host, msg)
|
|
|
|
return ReturnData(host=host, comm_ok=False, result=dict(failed=True, msg=msg))
|
|
|
|
return ReturnData(host=host, comm_ok=False, result=dict(failed=True, msg=msg), flags=get_flags())
|
|
|
|
|
|
|
|
|
|
|
|
# *****************************************************
|
|
|
|
# *****************************************************
|
|
|
|
|
|
|
|
|
|
|
@ -353,7 +371,7 @@ class Runner(object):
|
|
|
|
if items_plugin is not None and items_plugin in utils.plugins.lookup_loader:
|
|
|
|
if items_plugin is not None and items_plugin in utils.plugins.lookup_loader:
|
|
|
|
|
|
|
|
|
|
|
|
items_terms = self.module_vars.get('items_lookup_terms', '')
|
|
|
|
items_terms = self.module_vars.get('items_lookup_terms', '')
|
|
|
|
items_terms = utils.template(self.basedir, items_terms, inject)
|
|
|
|
items_terms = template.template(self.basedir, items_terms, inject)
|
|
|
|
items = utils.plugins.lookup_loader.get(items_plugin, runner=self, basedir=self.basedir).run(items_terms, inject=inject)
|
|
|
|
items = utils.plugins.lookup_loader.get(items_plugin, runner=self, basedir=self.basedir).run(items_terms, inject=inject)
|
|
|
|
if type(items) != list:
|
|
|
|
if type(items) != list:
|
|
|
|
raise errors.AnsibleError("lookup plugins have to return a list: %r" % items)
|
|
|
|
raise errors.AnsibleError("lookup plugins have to return a list: %r" % items)
|
|
|
@ -423,9 +441,9 @@ class Runner(object):
|
|
|
|
new_args = new_args + "%s='%s' " % (k,v)
|
|
|
|
new_args = new_args + "%s='%s' " % (k,v)
|
|
|
|
module_args = new_args
|
|
|
|
module_args = new_args
|
|
|
|
|
|
|
|
|
|
|
|
module_name = utils.template(self.basedir, module_name, inject)
|
|
|
|
module_name = template.template(self.basedir, module_name, inject)
|
|
|
|
module_args = utils.template(self.basedir, module_args, inject)
|
|
|
|
module_args = template.template(self.basedir, module_args, inject)
|
|
|
|
complex_args = utils.template(self.basedir, complex_args, inject)
|
|
|
|
complex_args = template.template(self.basedir, complex_args, inject)
|
|
|
|
|
|
|
|
|
|
|
|
if module_name in utils.plugins.action_loader:
|
|
|
|
if module_name in utils.plugins.action_loader:
|
|
|
|
if self.background != 0:
|
|
|
|
if self.background != 0:
|
|
|
@ -436,7 +454,7 @@ class Runner(object):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
handler = utils.plugins.action_loader.get('async', self)
|
|
|
|
handler = utils.plugins.action_loader.get('async', self)
|
|
|
|
|
|
|
|
|
|
|
|
conditional = utils.template(self.basedir, self.conditional, inject, expand_lists=False)
|
|
|
|
conditional = template.template(self.basedir, self.conditional, inject, expand_lists=False)
|
|
|
|
|
|
|
|
|
|
|
|
if not utils.check_conditional(conditional):
|
|
|
|
if not utils.check_conditional(conditional):
|
|
|
|
result = utils.jsonify(dict(skipped=True))
|
|
|
|
result = utils.jsonify(dict(skipped=True))
|
|
|
@ -457,7 +475,7 @@ class Runner(object):
|
|
|
|
# and we need to transfer those, and only those, variables
|
|
|
|
# and we need to transfer those, and only those, variables
|
|
|
|
delegate_to = inject.get('delegate_to', None)
|
|
|
|
delegate_to = inject.get('delegate_to', None)
|
|
|
|
if delegate_to is not None:
|
|
|
|
if delegate_to is not None:
|
|
|
|
delegate_to = utils.template(self.basedir, delegate_to, inject)
|
|
|
|
delegate_to = template.template(self.basedir, delegate_to, inject)
|
|
|
|
inject = inject.copy()
|
|
|
|
inject = inject.copy()
|
|
|
|
interpreters = []
|
|
|
|
interpreters = []
|
|
|
|
for i in inject:
|
|
|
|
for i in inject:
|
|
|
@ -481,8 +499,8 @@ class Runner(object):
|
|
|
|
actual_host = delegate_to
|
|
|
|
actual_host = delegate_to
|
|
|
|
actual_port = port
|
|
|
|
actual_port = port
|
|
|
|
|
|
|
|
|
|
|
|
actual_user = utils.template(self.basedir, actual_user, inject)
|
|
|
|
actual_user = template.template(self.basedir, actual_user, inject)
|
|
|
|
actual_pass = utils.template(self.basedir, actual_pass, inject)
|
|
|
|
actual_pass = template.template(self.basedir, actual_pass, inject)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if actual_port is not None:
|
|
|
|
if actual_port is not None:
|
|
|
|