當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。