def _execute_module(self, conn, tmp, remote_module_path, args, async_jid=None, async_module=None, async_limit=None): """ runs a module that has already been transferred """ inject = self.setup_cache.get(conn.host, {}).copy() host_variables = self.inventory.get_variables(conn.host) inject.update(host_variables) inject.update(self.module_vars) conditional = utils.double_template(self.conditional, inject, self.setup_cache) if not eval(conditional): return [utils.smjson(dict(skipped=True)), None, "skipped"] if self.module_name == "setup": if not args: args = {} args = self._add_setup_vars(inject, args) args = self._add_setup_metadata(args) if type(args) == dict: args = utils.bigjson(args) args = utils.template(args, inject, self.setup_cache) module_name_tail = remote_module_path.split("/")[-1] argsfile = self._transfer_str(conn, tmp, "arguments", args) if async_jid is None: cmd = "%s %s" % (remote_module_path, argsfile) else: cmd = " ".join([str(x) for x in [remote_module_path, async_jid, async_limit, async_module, argsfile]]) res, err = self._exec_command(conn, cmd, tmp, sudoable=True) client_executed_str = "%s %s" % (module_name_tail, args.strip()) return (res, err, client_executed_str)
def _execute_module(self, conn, tmp, remote_module_path, args, async_jid=None, async_module=None, async_limit=None): ''' runs a module that has already been transferred ''' inject = self.setup_cache.get(conn.host,{}) conditional = utils.double_template(self.conditional, inject, self.setup_cache) if not eval(conditional): return [ utils.smjson(dict(skipped=True)), None, 'skipped' ] host_variables = self.inventory.get_variables(conn.host) inject.update(host_variables) if self.module_name == 'setup': args = self._add_setup_vars(inject, args) args = self._add_setup_metadata(args) if type(args) == dict: args = utils.bigjson(args) args = utils.template(args, inject, self.setup_cache) module_name_tail = remote_module_path.split("/")[-1] argsfile = self._transfer_str(conn, tmp, 'arguments', args) if async_jid is None: cmd = "%s %s" % (remote_module_path, argsfile) else: cmd = " ".join([str(x) for x in [remote_module_path, async_jid, async_limit, async_module, argsfile]]) res, err = self._exec_command(conn, cmd, tmp, sudoable=True) client_executed_str = "%s %s" % (module_name_tail, args.strip()) return ( res, err, client_executed_str )
def _execute_module(self, conn, tmp, remote_module_path, args, async_jid=None, async_module=None, async_limit=None): ''' runs a module that has already been transferred ''' inject = self.setup_cache.get(conn.host,{}) conditional = utils.double_template(self.conditional, inject) if not eval(conditional): return [ utils.smjson(dict(skipped=True)), None, 'skipped' ] if Runner._external_variable_script is not None: self._add_variables_from_script(conn, inject) if self.module_name == 'setup': args = self._add_setup_vars(inject, args) args = self._add_setup_metadata(args) if type(args) == dict: args = utils.bigjson(args) args = utils.template(args, inject) module_name_tail = remote_module_path.split("/")[-1] argsfile = self._transfer_str(conn, tmp, 'arguments', args) if async_jid is None: cmd = "%s %s" % (remote_module_path, argsfile) else: cmd = " ".join([str(x) for x in [remote_module_path, async_jid, async_limit, async_module, argsfile]]) res, err = self._exec_command(conn, cmd, tmp, sudoable=True) client_executed_str = "%s %s" % (module_name_tail, args.strip()) return ( res, err, client_executed_str )
def _execute_module(self, conn, tmp, remote_module_path, args, async_jid=None, async_module=None, async_limit=None): """ runs a module that has already been transferred """ args = self._coerce_args_to_string(args, remote_module_path) inject = self.setup_cache.get(conn.host, {}) conditional = utils.double_template(self.conditional, inject) if not eval(conditional): return [utils.smjson(dict(skipped=True)), "skipped"] if Runner._external_variable_script is not None: self._add_variables_from_script(conn, inject) if self.module_name == "setup": args = self._add_setup_vars(inject, args) args = self._add_setup_metadata(args) args = utils.template(args, inject) module_name_tail = remote_module_path.split("/")[-1] client_executed_str = "%s %s" % (module_name_tail, args.strip()) argsfile = self._transfer_argsfile(conn, tmp, args) if async_jid is None: cmd = "%s %s" % (remote_module_path, argsfile) else: cmd = " ".join([str(x) for x in [remote_module_path, async_jid, async_limit, async_module, argsfile]]) return [self._exec_command(conn, cmd), client_executed_str]
def _executor_internal(self, host): ''' callback executed in parallel for each host. returns (hostname, connected_ok, extra) ''' host_variables = self.inventory.get_variables(host) port = host_variables.get('ansible_ssh_port', self.remote_port) inject = self.setup_cache.get(host,{}).copy() inject.update(host_variables) inject.update(self.module_vars) conditional = utils.double_template(self.conditional, inject, self.setup_cache) if not eval(conditional): result = utils.smjson(dict(skipped=True)) self.callbacks.on_skipped(host) return ReturnData(host=host, result=result) conn = None try: conn = self.connector.connect(host, port) except errors.AnsibleConnectionFailed, e: result = dict(failed=True, msg="FAILED: %s" % str(e)) return ReturnData(host=host, comm_ok=False, result=result)
else: if not 'metadata' in args: if self.remote_user == 'root': args['metadata'] = '/etc/ansible/setup' else: args['metadata'] = "/home/%s/.ansible/setup" % (self.remote_user) return args # ***************************************************** def _execute_module(self, conn, tmp, remote_module_path, args, async_jid=None, async_module=None, async_limit=None): ''' runs a module that has already been transferred ''' inject = self.setup_cache.get(conn.host,{}) conditional = utils.double_template(self.conditional, inject) if not eval(conditional): return [ utils.smjson(dict(skipped=True)), None, 'skipped' ] host_variables = self.inventory.get_variables(conn.host, self.extra_vars) inject.update(host_variables) if self.module_name == 'setup': args = self._add_setup_vars(inject, args) args = self._add_setup_metadata(args) if type(args) == dict: args = utils.bigjson(args) args = utils.template(args, inject) module_name_tail = remote_module_path.split("/")[-1]