Exemple #1
0
    def compile(self):
        '''
        Compiles and returns the task list for this play, compiled from the
        roles (which are themselves compiled recursively) and/or the list of
        tasks specified in the play.
        '''

        task_list = []

        task_list.extend(compile_block_list(self.pre_tasks))
        task_list.extend(self._compile_roles())
        task_list.extend(compile_block_list(self.tasks))
        task_list.extend(compile_block_list(self.post_tasks))

        return task_list
    def compile(self):
        '''
        Compiles and returns the task list for this play, compiled from the
        roles (which are themselves compiled recursively) and/or the list of
        tasks specified in the play.
        '''

        task_list = []

        task_list.extend(compile_block_list(self.pre_tasks))
        task_list.extend(self._compile_roles())
        task_list.extend(compile_block_list(self.tasks))
        task_list.extend(compile_block_list(self.post_tasks))

        return task_list
Exemple #3
0
    def _load_included_file(self, included_file):
        '''
        Loads an included YAML file of tasks, applying the optional set of variables.
        '''

        data = self._loader.load_from_file(included_file._filename)
        if not isinstance(data, list):
            raise AnsibleParsingError(
                "included task files must contain a list of tasks",
                obj=included_file._task._ds)

        is_handler = isinstance(included_file._task, Handler)
        block_list = load_list_of_blocks(
            data,
            parent_block=included_file._task._block,
            task_include=included_file._task,
            role=included_file._task._role,
            use_handlers=is_handler,
            loader=self._loader)

        task_list = compile_block_list(block_list)

        # set the vars for this task from those specified as params to the include
        for t in task_list:
            t.vars = included_file._args.copy()

        return task_list
Exemple #4
0
    def compile(self, dep_chain=[]):
        '''
        Returns the task list for this role, which is created by first
        recursively compiling the tasks for all direct dependencies, and
        then adding on the tasks for this role.

        The role compile() also remembers and saves the dependency chain
        with each task, so tasks know by which route they were found, and
        can correctly take their parent's tags/conditionals into account.
        '''

        task_list = []

        # update the dependency chain here
        new_dep_chain = dep_chain + [self]

        deps = self.get_direct_dependencies()
        for dep in deps:
            dep_tasks = dep.compile(dep_chain=new_dep_chain)
            for dep_task in dep_tasks:
                # since we're modifying the task, and need it to be unique,
                # we make a copy of it here and assign the dependency chain
                # to the copy, then append the copy to the task list.
                new_dep_task = dep_task.copy()
                new_dep_task._dep_chain = new_dep_chain
                task_list.append(new_dep_task)

        task_list.extend(compile_block_list(self._task_blocks))

        return task_list
Exemple #5
0
    def _load_included_file(self, included_file):
        '''
        Loads an included YAML file of tasks, applying the optional set of variables.
        '''

        data = self._loader.load_from_file(included_file._filename)
        if not isinstance(data, list):
            raise AnsibleParsingError("included task files must contain a list of tasks", obj=included_file._task._ds)

        is_handler = isinstance(included_file._task, Handler)
        block_list = load_list_of_blocks(
            data,
            parent_block=included_file._task._block,
            task_include=included_file._task,
            role=included_file._task._role,
            use_handlers=is_handler,
            loader=self._loader
        )


        task_list = compile_block_list(block_list)

        # set the vars for this task from those specified as params to the include
        for t in task_list:
            t.vars = included_file._args.copy()

        return task_list
Exemple #6
0
    def compile(self):
        '''
        Returns the task list for the included tasks.
        '''

        task_list = []
        task_list.extend(compile_block_list(self._task_blocks))
        return task_list
Exemple #7
0
    def compile(self):
        '''
        Returns the task list for the included tasks.
        '''

        task_list = []
        task_list.extend(compile_block_list(self._task_blocks))
        return task_list
Exemple #8
0
    def compile(self):
        '''
        Returns the task list for this role, which is created by first
        recursively compiling the tasks for all direct dependencies, and
        then adding on the tasks for this role.
        '''

        task_list = []

        deps = self.get_direct_dependencies()
        for dep in deps:
            task_list.extend(dep.compile())

        task_list.extend(compile_block_list(self._task_blocks))

        return task_list
Exemple #9
0
    def compile(self):
        '''
        Returns the task list for this role, which is created by first
        recursively compiling the tasks for all direct dependencies, and
        then adding on the tasks for this role.
        '''

        task_list = []

        deps = self.get_direct_dependencies()
        for dep in deps:
            task_list.extend(dep.compile())

        task_list.extend(compile_block_list(self._task_blocks))

        return task_list
    def run_handlers(self, iterator, connection_info):
        '''
        Runs handlers on those hosts which have been notified.
        '''

        result = True

        # FIXME: getting the handlers from the iterators play should be
        #        a method on the iterator, which may also filter the list
        #        of handlers based on the notified list
        handlers = compile_block_list(iterator._play.handlers)

        debug("handlers are: %s" % handlers)
        for handler in handlers:
            handler_name = handler.get_name()

            if handler_name in self._notified_handlers and len(
                    self._notified_handlers[handler_name]):
                if not len(self.get_hosts_remaining(iterator._play)):
                    self._callback.playbook_on_no_hosts_remaining()
                    result = False
                    break

                self._callback.playbook_on_handler_task_start(handler_name)
                for host in self._notified_handlers[handler_name]:
                    if not handler.has_triggered(host):
                        task_vars = self._variable_manager.get_vars(
                            loader=self._loader,
                            play=iterator._play,
                            host=host,
                            task=handler)
                        self._queue_task(host, handler, task_vars,
                                         connection_info)
                        handler.flag_for_host(host)

                    self._process_pending_results(iterator)

                self._wait_on_pending_results(iterator)

                # wipe the notification list
                self._notified_handlers[handler_name] = []

        debug("done running handlers, result is: %s" % result)
        return result
Exemple #11
0
    def run_handlers(self, iterator, connection_info):
        '''
        Runs handlers on those hosts which have been notified.
        '''

        result = True

        # FIXME: getting the handlers from the iterators play should be
        #        a method on the iterator, which may also filter the list
        #        of handlers based on the notified list
        handlers = compile_block_list(iterator._play.handlers)

        debug("handlers are: %s" % handlers)
        for handler in handlers:
            handler_name = handler.get_name()

            if handler_name in self._notified_handlers and len(self._notified_handlers[handler_name]):
                if not len(self.get_hosts_remaining(iterator._play)):
                    self._callback.playbook_on_no_hosts_remaining()
                    result = False
                    break

                self._callback.playbook_on_handler_task_start(handler_name)
                for host in self._notified_handlers[handler_name]:
                    if not handler.has_triggered(host):
                        task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=handler)
                        self._queue_task(host, handler, task_vars, connection_info)
                        handler.flag_for_host(host)

                    self._process_pending_results(iterator)

                self._wait_on_pending_results(iterator)

                # wipe the notification list
                self._notified_handlers[handler_name] = []

        debug("done running handlers, result is: %s" % result)
        return result
    def _load_included_file(self, task, include_file, include_vars):
        '''
        Loads an included YAML file of tasks, applying the optional set of variables.
        '''

        data = self._loader.load_from_file(include_file)
        if not isinstance(data, list):
            raise AnsibleParsingError(
                "included task files must contain a list of tasks", obj=ds)

        is_handler = isinstance(task, Handler)

        block_list = load_list_of_blocks(data,
                                         parent_block=task._block,
                                         task_include=task,
                                         role=task._role,
                                         use_handlers=is_handler,
                                         loader=self._loader)

        task_list = compile_block_list(block_list)
        for t in task_list:
            t.vars = include_vars.copy()

        return task_list