Esempio n. 1
0
    def run(self, tmp=None, task_vars=None):
        # we need the zuul_log_id on shell and command tasks
        host = paths._sanitize_filename(task_vars.get('inventory_hostname'))
        if self._task.action in ('command', 'shell'):
            self._task.args['zuul_log_id'] = "%s-%s" % (self._task._uuid, host)

        return super(ActionModule, self).run(tmp, task_vars)
Esempio n. 2
0
    def v2_playbook_on_task_start(self, task, is_conditional):
        # Log an extra blank line to get space before each task
        self._log("")

        self._task = task

        if self._play.strategy != 'free':
            task_name = self._print_task_banner(task)
        else:
            task_name = task.get_name().strip()

        if task.action in ('command', 'shell'):
            play_vars = self._play._variable_manager._hostvars

            hosts = self._get_task_hosts(task)
            for host, inventory_hostname in hosts:
                if host in ('localhost', '127.0.0.1'):
                    # Don't try to stream from localhost
                    continue
                ip = play_vars[host].get(
                    'ansible_host',
                    play_vars[host].get('ansible_inventory_host'))
                if ip in ('localhost', '127.0.0.1'):
                    # Don't try to stream from localhost
                    continue
                log_id = "%s-%s" % (
                    task._uuid, paths._sanitize_filename(inventory_hostname))
                streamer = threading.Thread(target=self._read_log,
                                            args=(host, ip, log_id, task_name,
                                                  hosts))
                streamer.daemon = True
                streamer.start()
                self._streamers.append(streamer)
Esempio n. 3
0
    def run(self, tmp=None, task_vars=None):
        if paths._is_localhost_task(self):
            raise AnsibleError("Executing local code is prohibited")

        # we need the zuul_log_id on shell and command tasks
        host = paths._sanitize_filename(task_vars.get('inventory_hostname'))
        if self._task.action in ('command', 'shell'):
            self._task.args['zuul_log_id'] = "%s-%s" % (self._task._uuid, host)

        return super(ActionModule, self).run(tmp, task_vars)
Esempio n. 4
0
    def v2_playbook_on_task_start(self, task, is_conditional):
        # Log an extra blank line to get space before each task
        self._log("")

        self._task = task

        if self._play.strategy != 'free':
            task_name = self._print_task_banner(task)
        else:
            task_name = task.get_name().strip()

        if task.action in ('command', 'shell'):
            play_vars = self._play._variable_manager._hostvars

            hosts = self._get_task_hosts(task)
            for host, inventory_hostname in hosts:
                port = LOG_STREAM_PORT
                if host in ('localhost', '127.0.0.1'):
                    # Don't try to stream from localhost
                    continue
                ip = play_vars[host].get(
                    'ansible_host', play_vars[host].get(
                        'ansible_inventory_host'))
                if ip in ('localhost', '127.0.0.1'):
                    # Don't try to stream from localhost
                    continue
                if task.loop:
                    # Don't try to stream from loops
                    continue
                if play_vars[host].get('ansible_connection') in ('winrm',):
                    # The winrm connections don't support streaming for now
                    continue
                if play_vars[host].get('ansible_connection') in ('kubectl', ):
                    # Stream from the forwarded port on kubectl conns
                    port = play_vars[host]['zuul']['resources'][
                        inventory_hostname].get('stream_port')
                    if port is None:
                        self._log("[Zuul] Kubectl and socat must be installed "
                                  "on the Zuul executor for streaming output "
                                  "from pods")
                        continue
                    ip = '127.0.0.1'

                log_id = "%s-%s" % (
                    task._uuid, paths._sanitize_filename(inventory_hostname))
                streamer = threading.Thread(
                    target=self._read_log, args=(
                        host, ip, port, log_id, task_name, hosts))
                streamer.daemon = True
                streamer.start()
                self._streamers.append(streamer)
Esempio n. 5
0
    def v2_playbook_on_task_start(self, task, is_conditional):
        # Log an extra blank line to get space before each task
        self._log("")

        self._task = task

        if self._play.strategy != 'free':
            task_name = self._print_task_banner(task)
        else:
            task_name = task.get_name().strip()

        if task.action in ('command', 'shell'):
            play_vars = self._play._variable_manager._hostvars

            hosts = self._get_task_hosts(task)
            for host, inventory_hostname in hosts:
                if host in ('localhost', '127.0.0.1'):
                    # Don't try to stream from localhost
                    continue
                ip = play_vars[host].get(
                    'ansible_host', play_vars[host].get(
                        'ansible_inventory_host'))
                if ip in ('localhost', '127.0.0.1'):
                    # Don't try to stream from localhost
                    continue
                if task.loop:
                    # Don't try to stream from loops
                    continue
                if play_vars[host].get('ansible_connection') in ('kubectl', ):
                    # Don't try to stream from kubectl connection
                    continue

                log_id = "%s-%s" % (
                    task._uuid, paths._sanitize_filename(inventory_hostname))
                streamer = threading.Thread(
                    target=self._read_log, args=(
                        host, ip, log_id, task_name, hosts))
                streamer.daemon = True
                streamer.start()
                self._streamers.append(streamer)