'Run list of commands on remote device and return results'

def run_commands(self, commands, check_rc=True):

    responses = list()
    for item in to_list(commands):
        if ((item['output'] == 'json') and (not is_json(item['command']))):
            cmd = ('%s    |    json' % item['command'])
        elif ((item['output'] == 'text') and is_json(item['command'])):
            cmd = item['command'].split('|')[0]
        else:
            cmd = item['command']
        (rc, out, err) = self.exec_command(cmd)
        out = to_text(out, errors='surrogate_then_replace')
        if (check_rc and (rc != 0)):
            self._module.fail_json(msg=to_text(err, errors='surrogate_then_replace'))
        try:
            out = self._module.from_json(out)
        except ValueError:
            out = str(out).strip()
        responses.append(out)
    return responses
