Exemple #1
0
    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 )
Exemple #3
0
    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]
Exemple #4
0
    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 _transfer_str(self, conn, tmp, name, data):
        ''' transfer string to remote file '''

        if type(data) == dict:
            data = utils.smjson(data)

        afd, afile = tempfile.mkstemp()
        afo = os.fdopen(afd, 'w')
        afo.write(data.encode("utf8"))
        afo.flush()
        afo.close()

        remote = os.path.join(tmp, name)
        conn.put_file(afile, remote)
        os.unlink(afile)
        return remote
Exemple #6
0
    def _transfer_str(self, conn, tmp, name, data):
        """ transfer string to remote file """

        if type(data) == dict:
            data = utils.smjson(data)

        afd, afile = tempfile.mkstemp()
        afo = os.fdopen(afd, "w")
        afo.write(data.encode("utf8"))
        afo.flush()
        afo.close()

        remote = os.path.join(tmp, name)
        conn.put_file(afile, remote)
        os.unlink(afile)
        return remote
Exemple #7
0
    def _transfer_str(self, conn, tmp, name, args_str):
        ''' transfer arguments as a single file to be fed to the module. '''

        if type(args_str) == dict:
            args_str = utils.smjson(args_str)

        args_fd, args_file = tempfile.mkstemp()
        args_fo = os.fdopen(args_fd, 'w')
        args_fo.write(args_str)
        args_fo.flush()
        args_fo.close()

        args_remote = os.path.join(tmp, name)
        conn.put_file(args_file, args_remote)
        os.unlink(args_file)

        return args_remote
    def _transfer_str(self, conn, tmp, name, args_str):
        ''' transfer arguments as a single file to be fed to the module. '''

        if type(args_str) == dict:
            args_str = utils.smjson(args_str)

        args_fd, args_file = tempfile.mkstemp()
        args_fo = os.fdopen(args_fd, 'w')
        args_fo.write(args_str)
        args_fo.flush()
        args_fo.close()

        args_remote = os.path.join(tmp, name)
        conn.put_file(args_file, args_remote)
        os.unlink(args_file)

        return args_remote
    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)
Exemple #10
0
    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.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)
                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]

        argsfile = self._transfer_str(conn, tmp, 'arguments', args)