当前位置: 首页>>代码示例>>Python>>正文


Python task_queue_manager.TaskQueueManager方法代码示例

本文整理汇总了Python中ansible.executor.task_queue_manager.TaskQueueManager方法的典型用法代码示例。如果您正苦于以下问题:Python task_queue_manager.TaskQueueManager方法的具体用法?Python task_queue_manager.TaskQueueManager怎么用?Python task_queue_manager.TaskQueueManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ansible.executor.task_queue_manager的用法示例。


在下文中一共展示了task_queue_manager.TaskQueueManager方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def __init__(self, playbook, inventory, variable_manager,
                 loader, options, passwords, output):
        self._playbook = playbook
        self._inventory = inventory
        self._variable_manager = variable_manager
        self._loader = loader
        self._options = options
        self.passwords = passwords
        self._unreachable_hosts = dict()

        try:
            self._tqm = TaskQueueManager(inventory=inventory,
                                         variable_manager=variable_manager,
                                         loader=loader, options=options,
                                         passwords=self.passwords,
                                         stdout_callback=AnsibleCallbacks(output))
        except TypeError:
            # In case of ansible 2.8 options parameter has been removed
            self._tqm = TaskQueueManager(inventory=inventory,
                                         variable_manager=variable_manager,
                                         loader=loader,
                                         passwords=self.passwords,
                                         stdout_callback=AnsibleCallbacks(output)) 
开发者ID:grycap,项目名称:im,代码行数:25,代码来源:ansible_executor_v2.py

示例2: _execute_play

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def _execute_play(play_source, inventory, var_mgr, loader, options, callback):  # pylint: disable=too-many-arguments
    """
    Execute the playbook
    """
    play = Play().load(play_source, variable_manager=var_mgr, loader=loader)
    tqm = None
    try:
      tqm = TaskQueueManager(
          inventory=inventory,
          variable_manager=var_mgr,
          loader=loader,
          options=options,
          passwords=None,
          stdout_callback=callback,
          )
      _ = tqm.run(play)
    except Exception as exc:
      raise TaskExecutionException(str(exc))
    finally:
      if tqm is not None:
        tqm.cleanup() 
开发者ID:aacebedo,项目名称:i3-xfce,代码行数:23,代码来源:core.py

示例3: run

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run(self):
        # actually run it
        tqm = None
        try:
            tqm = TaskQueueManager(
                inventory=self.inventory,
                variable_manager=self.variable_manager,
                loader=self.loader,
                options=self.options,
                passwords=dict(),
            )
            tqm._stdout_callback = self.call_back
            result = tqm.run(self.play)
            self._summary = self.call_back.summary
            self._results = self.call_back.results
            return result
        finally:
            if tqm is not None:
                tqm.cleanup() 
开发者ID:510908220,项目名称:heartbeats,代码行数:21,代码来源:ansible_task.py

示例4: run

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run(self):
        tqm = None
        try:
            tqm = TaskQueueManager(
                inventory = self.inventory,
                variable_manager = self.variable_manager,
                loader = self.loader,
                options = self.options,
                passwords = {},
                stdout_callback = self.stdout_callback
            )
            for p in self.play:
                result = tqm.run(p)
            self.delete_key()
        finally:
            if tqm is not None:
                tqm.cleanup() 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:19,代码来源:playbook.py

示例5: run

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run(self):
        # running the playbook
        tqm = None
        try:
            tqm = TaskQueueManager(
                    inventory=self.inventory,
                    variable_manager=self.variable_manager,
                    loader=self.loader,
                    options=self.options,
                    passwords={},
                    # stdout_callback="default",
                    stdout_callback=self.callback,
                )
            self.rc = tqm.run(self.playbook)

        finally:
            if tqm is not None:
                tqm.cleanup() 
开发者ID:pcuzner,项目名称:ceph-ansible-copilot,代码行数:20,代码来源:playbook.py

示例6: run_adhoc

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run_adhoc(self, hosts, module_name, module_args=''):
        ###########################
        # run module from andible ad-hoc.
        ##########################
        play_source = dict(
            name="Ansible Play",
            hosts=hosts,
            gather_facts='no',
            tasks=[dict(action=dict(module=module_name, args=module_args))]
        )
        play = Play().load(play_source, variable_manager=self.variable_manager, loader=self.loader)

        # actually run it
        tqm = None
        try:
            tqm = TaskQueueManager(
                inventory=self.inventory,
                variable_manager=self.variable_manager,
                loader=self.loader,
                options=self.options,
                passwords=self.passwords,
                stdout_callback=self.callback,
            )
            tqm.run(play)
        finally:
            if tqm is not None:
                tqm.cleanup() 
开发者ID:JiaJunZz,项目名称:swallow,代码行数:29,代码来源:ansible_api.py

示例7: run_model

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run_model(self, host_list, module_name, module_args):
        """
        run module from andible ad-hoc.
        module_name: ansible module_name
        module_args: ansible module args
        """
        play_source = dict(
                name="Ansible Play",
                hosts=host_list,
                gather_facts='no',
                tasks=[dict(action=dict(module=module_name, args=module_args))]
        )

        play = Play().load(play_source, variable_manager=self.variable_manager, loader=self.loader)
        tqm = None
        # if self.redisKey:self.callback = ModelResultsCollectorToSave(self.redisKey,self.logId)
        # else:self.callback = ModelResultsCollector()
        self.callback = ModelResultsCollector()
        import traceback
        try:
            tqm = TaskQueueManager(
                    inventory=self.inventory,
                    variable_manager=self.variable_manager,
                    loader=self.loader,
                    options=self.options,
                    passwords=self.passwords,
                    stdout_callback = "minimal",
            )
            tqm._stdout_callback = self.callback
            constants.HOST_KEY_CHECKING = False #关闭第一次使用ansible连接客户端是输入命令
            tqm.run(play)
        except Exception as err:
            print traceback.print_exc()
            # DsRedis.OpsAnsibleModel.lpush(self.redisKey,data=err)
            # if self.logId:AnsibleSaveResult.Model.insert(self.logId, err)
        finally:
            if tqm is not None:
                tqm.cleanup() 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:40,代码来源:ansible_api.py

示例8: run

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run(self, tasks, pattern, play_name='Ansible Ad-hoc', gather_facts='no'):
        """
        :param tasks: [{'action': {'module': 'shell', 'args': 'ls'}, ...}, ]
        :param pattern: all, *, or others
        :param play_name: The play name
        :param gather_facts:
        :return:
        """
        self.check_pattern(pattern)
        cleaned_tasks = self.clean_tasks(tasks)

        play_source = dict(
            name=play_name,
            hosts=pattern,
            gather_facts=gather_facts,
            tasks=cleaned_tasks
        )

        play = Play().load(
            play_source,
            variable_manager=self.variable_manager,
            loader=self.loader,
        )

        tqm = TaskQueueManager(
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            stdout_callback=self.results_callback,
            passwords=self.options.passwords,
        )
        msg = ("Get matched hosts: {}".format(
            self.inventory.get_matched_hosts(pattern)
        ))
        try:
            tqm.send_callback('on_playbook_start', play.name)
            self.results_callback.display(msg)
            tqm.run(play)
            return self.results_callback.results
        except Exception as e:
            raise AnsibleError(e)
        finally:
            tqm.send_callback('v2_playbook_on_stats', tqm._stats)
            tqm.send_callback('on_playbook_end', play.name)
            tqm.cleanup()
            self.loader.cleanup_all_tmp_files() 
开发者ID:KubeOperator,项目名称:KubeOperator,代码行数:49,代码来源:runner.py

示例9: run

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run(self, inventory_content, pattern='all'):
        
        '''
        运行adhoc
        '''
        
        self.pattern = pattern
        self.inventory_content = inventory_content
        if not self.options.module_name :
            self.logger.error(self.log_prefix + '准备工作失败,原因:执行模块不能为空')
            return (False, '执行模块不能为空,请输入模块名')
        else: 
            if self.options.module_name in C.MODULE_REQUIRE_ARGS and not self.options.module_args :
                self.logger.error(self.log_prefix + '准备工作失败,原因:执行模块参数为空')
                return (False, '执行模块参数为空,请输入模块参数')

        for name, obj in get_all_plugin_loaders():
            name = name
            if obj.subdir:
                plugin_path = os.path.join('.', obj.subdir)
                if os.path.isdir(plugin_path):
                    obj.add_directory(plugin_path)
        
        self._gen_tasks()

        play = Play().load(self.tasks_dict, variable_manager=self.variable_manager, loader=self.loader)

        try :
            self.host_list = self.inventory.list_hosts(self.pattern)
        except :
            self.host_list = []
            
        if len(self.host_list) == 0 :
            self.logger.error(self.log_prefix + '准备工作失败,原因:没有匹配主机名')
            return (False, '执行失败,没有匹配主机名')
        
        self._loading_callback()
        
        self._tqm = None
        try:
            self._tqm = TaskQueueManager(
                inventory=self.inventory,
                variable_manager=self.variable_manager,
                loader=self.loader,
                options=self.options,
                passwords=self.passwords,
                stdout_callback=self.callback,
                # run_additional_callbacks=C.DEFAULT_LOAD_CALLBACK_PLUGINS,
                # run_tree=False,
            )
            self._tqm.run(play)
        finally:
            if self._tqm:
                self._tqm.cleanup()
                
            if self.loader:
                self.loader.cleanup_all_tmp_files()

        self.logger.info(self.log_prefix + '发送成功')
        return True 
开发者ID:lykops,项目名称:lykops,代码行数:62,代码来源:adhoc.py

示例10: run_module

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run_module(self, module_name='ping', module_args=None, hosts="all",
                   inventory_file=None, **kwargs):

        if not module_args:
            check_raw = module_name in ('command', 'win_command', 'shell',
                                        'win_shell', 'script', 'raw')
            module_args = parse_kv(constants.DEFAULT_MODULE_ARGS, check_raw)

        conn_pass = None
        if 'conn_pass' in kwargs:
            conn_pass = kwargs['conn_pass']

        become_pass = None
        if 'become_pass' in kwargs:
            become_pass = kwargs['become_pass']

        passwords = {'conn_pass': conn_pass, 'become_pass': become_pass}

        options = self._build_opt_dict(inventory_file, **kwargs)

        variable_manager = vars.VariableManager()
        loader = dataloader.DataLoader()
        variable_manager.extra_vars = options.extra_vars

        ansible_inv = inventory.Inventory(loader=loader,
                                          variable_manager=variable_manager,
                                          host_list=options.inventory)
        variable_manager.set_inventory(ansible_inv)
        ansible_inv.subset(options.subset)

        play_ds = self._play_ds(hosts, module_name, module_args)
        play_obj = play.Play().load(play_ds, variable_manager=variable_manager,
                                    loader=loader)

        try:
            tqm = task_queue_manager.TaskQueueManager(
                inventory=ansible_inv,
                variable_manager=variable_manager,
                loader=loader,
                options=options,
                passwords=passwords,
                stdout_callback='minimal',
                run_additional_callbacks=True
            )

            # There is no public API for adding callbacks, hence we use a
            # private property to add callbacks
            tqm._callback_plugins.extend(self._callbacks)

            result = tqm.run(play_obj)
        finally:
            if tqm:
                tqm.cleanup()
            if loader:
                loader.cleanup_all_tmp_files()

        stats = tqm._stats
        result = self._process_stats(stats)
        return result 
开发者ID:vmware-archive,项目名称:column,代码行数:61,代码来源:api_runner.py

示例11: run

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run(
            self,
            tasks,
            pattern,
            play_name='Ansible Ad-hoc',
            gather_facts='no',):
        """
        :param gather_facts:
        :param tasks: [{'action': {'module': 'shell', 'args': 'ls'}, ...}, ]
        :param pattern: all, *, or others
        :param play_name: The play name
        :return:
        """
        self.check_pattern(pattern)
        results_callback = self.results_callback_class()
        cleaned_tasks = self.clean_tasks(tasks)

        play_source = dict(
            name=play_name,
            hosts=pattern,
            gather_facts=gather_facts,
            tasks=cleaned_tasks
        )

        play = Play().load(
            play_source,
            variable_manager=self.variable_manager,
            loader=self.loader,
        )

        tqm = TaskQueueManager(
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            stdout_callback=results_callback,
            passwords=self.options.passwords,
        )

        try:
            tqm.run(play)
            return results_callback
        except Exception as e:
            raise AnsibleError(e)
        finally:
            tqm.cleanup()
            self.loader.cleanup_all_tmp_files() 
开发者ID:hequan2017,项目名称:chain,代码行数:49,代码来源:runner.py

示例12: __init__

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def __init__(self, **kwargs):
        super(Ansible_playbook, self).__init__(**kwargs)

        self.task_file = kwargs.get('task_file', None)
        self.sudo = kwargs.get('sudo', False)
        self.sudo_user = kwargs.get('sudo_user', False)
        self.sudo_password = kwargs.get('sudo_password', False)

        # check if parameters have been provided
        if self._is_parameters_ok():
            # since the API is constructed for CLI it expects certain options to always be set in the context object
            context.CLIARGS = self._get_options()

            # initialize needed objects
            loader = DataLoader()

            passwords = {'become_pass': self.sudo_password}

            inventory = InventoryManager(loader=loader, sources="localhost,")

            # variable manager takes care of merging all the different sources to give you a unified
            # view of variables available in each context
            variable_manager = VariableManager(loader=loader, inventory=inventory)
            variable_manager.set_inventory(inventory)

            playbooks = None
            with open(self.task_file, 'r') as stream:
                try:
                    playbooks = yaml.full_load(stream)
                except yaml.YAMLError as exc:
                    logger.debug("Ansibe playbook error: {}".format(exc))

            if playbooks is not None:
                # force usage of python 3 interpreter
                playbooks[0].setdefault("vars", {})
                playbooks[0]["vars"]["ansible_python_interpreter"] = "/usr/bin/python3"

                play = Play().load(playbooks[0], variable_manager=variable_manager, loader=loader)

                # Run it - instantiate task queue manager, which takes care of forking and setting up all objects
                # to iterate over host list and tasks
                tqm = None
                try:
                    tqm = TaskQueueManager(
                        inventory=inventory,
                        variable_manager=variable_manager,
                        loader=loader,
                        passwords=passwords,
                        stdout_callback='default',
                        # Use our custom callback instead of the ``default`` callback plugin, which prints to stdout
                    )
                    tqm.run(play)  # most interesting data for a play is actually sent to the callback's methods
                finally:
                    # we always need to cleanup child procs and the structres we use to communicate with them
                    if tqm is not None:
                        tqm.cleanup() 
开发者ID:kalliope-project,项目名称:kalliope,代码行数:58,代码来源:ansible_playbook.py

示例13: run

# 需要导入模块: from ansible.executor import task_queue_manager [as 别名]
# 或者: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
def run(self, tasks, pattern, play_name='Ansible Ad-hoc', gather_facts='no'):
        """
        :param tasks: [{'action': {'module': 'shell', 'args': 'ls'}, ...}, ]
        :param pattern: all, *, or others
        :param play_name: The play name
        :return:
        """
        self.check_pattern(pattern)
        results_callback = self.results_callback_class()
        cleaned_tasks = self.clean_tasks(tasks)

        play_source = dict(
            name=play_name,
            hosts=pattern,
            gather_facts=gather_facts,
            tasks=cleaned_tasks
        )

        play = Play().load(
            play_source,
            variable_manager=self.variable_manager,
            loader=self.loader,
        )

        tqm = TaskQueueManager(
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            stdout_callback=results_callback,
            passwords=self.options.passwords,
        )


        try:
            tqm.run(play)
            return results_callback
        except Exception as e:
            raise AnsibleError(e)
        finally:
            tqm.cleanup()
            self.loader.cleanup_all_tmp_files() 
开发者ID:hequan2017,项目名称:autoops,代码行数:44,代码来源:runner.py


注:本文中的ansible.executor.task_queue_manager.TaskQueueManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。