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


Python TaskQueueManager._stdout_callback方法代码示例

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


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

示例1: run

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import _stdout_callback [as 别名]
    def run(self, host_list, module_name, module_args,):
        """
        run module from andible ad-hoc.
        module_name: ansible module_name
        module_args: ansible module args
        """
        # create play with tasks
        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)

        # actually run it
        tqm = None
        self.callback = ResultsCollector()
        try:
            tqm = TaskQueueManager(
                    inventory=self.inventory,
                    variable_manager=self.variable_manager,
                    loader=self.loader,
                    options=self.options,
                    passwords=self.passwords,
            )
            tqm._stdout_callback = self.callback
            result = tqm.run(play)
        finally:
            if tqm is not None:
                tqm.cleanup()
开发者ID:AutoOps,项目名称:MagicStack-Proxy,代码行数:33,代码来源:ansible_play.py

示例2: run_model

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import _stdout_callback [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()  
     try:  
         tqm = TaskQueueManager(  
                 inventory=self.inventory,  
                 variable_manager=self.variable_manager,  
                 loader=self.loader,  
                 options=self.options,  
                 passwords=self.passwords,  
         )  
         tqm._stdout_callback = self.callback  
         tqm.run(play)  
     finally:  
         if tqm is not None:  
             tqm.cleanup()  
开发者ID:gefeng24,项目名称:OpsManage,代码行数:31,代码来源:ansible_api_v2.py

示例3: run_model

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import _stdout_callback [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 or self.logId:self.callback = ModelResultsCollectorToSave(self.redisKey,self.logId)  
     else:self.callback = ModelResultsCollector()  
     try:  
         tqm = TaskQueueManager(  
                 inventory=self.inventory,  
                 variable_manager=self.variable_manager,  
                 loader=self.loader,  
                 options=self.options,  
                 passwords=self.passwords,  
         )  
         tqm._stdout_callback = self.callback  
         constants.HOST_KEY_CHECKING = False #关闭第一次使用ansible连接客户端是输入命令
         tqm.run(play)  
     except Exception as err: 
         if self.redisKey: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:YangDevops,项目名称:OpsManage,代码行数:36,代码来源:ansible_api_v2.py

示例4: main

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import _stdout_callback [as 别名]
def main():
    host_list = ['localhost', 'www.example.com', 'www.google.com']
    Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'remote_user',
                                     'private_key_file', 'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args',
                                     'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check'])

    # initialize needed objects
    variable_manager = VariableManager()
    loader = DataLoader()
    options = Options(connection='smart', module_path='/usr/share/ansible', forks=100,
                      remote_user=None, private_key_file=None, ssh_common_args=None, ssh_extra_args=None,
                      sftp_extra_args=None, scp_extra_args=None, become=None, become_method=None,
                      become_user=None, verbosity=None, check=False)

    passwords = dict()

    # create inventory and pass to var manager
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=host_list)
    variable_manager.set_inventory(inventory)

    # create play with tasks
    play_source = dict(
        name="Ansible Play",
        hosts=host_list,
        gather_facts='no',
        tasks=[dict(action=dict(module='command', args=dict(cmd='/usr/bin/uptime')))]
    )
    play = Play().load(play_source, variable_manager=variable_manager, loader=loader)

    # actually run it
    tqm = None
    callback = ResultsCollector()
    try:
        tqm = TaskQueueManager(
            inventory=inventory,
            variable_manager=variable_manager,
            loader=loader,
            options=options,
            passwords=passwords,
        )
        tqm._stdout_callback = callback
        result = tqm.run(play)
    finally:
        if tqm is not None:
            tqm.cleanup()

    print("UP ***********")
    for host, result in callback.host_ok.items():
        print('{} >>> {}'.format(host, result._result['stdout']))

    print("FAILED *******")
    for host, result in callback.host_failed.items():
        print('{} >>> {}'.format(host, result._result['msg']))

    print("DOWN *********")
    for host, result in callback.host_unreachable.items():
        print('{} >>> {}'.format(host, result._result['msg']))
开发者ID:ernstp,项目名称:ansible,代码行数:59,代码来源:uptime.py

示例5: main

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import _stdout_callback [as 别名]
def main(host_list,module,args):
    Options = namedtuple('Options', ['connection','module_path', 'forks', 'remote_user',
            'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args',
            'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check'])

    # initialize needed objects
    variable_manager = VariableManager()
    loader = DataLoader()
    options = Options(connection='smart', module_path='xxx', forks=50,
            remote_user='root', ssh_common_args=None, ssh_extra_args=None,
            sftp_extra_args=None, scp_extra_args=None, become=None, become_method=None,
            become_user=None, verbosity=None, check=False)

    passwords = dict(sshpass=None, becomepass=None)

    # create inventory and pass to var manager
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=host_list)
    variable_manager.set_inventory(inventory)

    # create play with tasks
    play_source =  dict(
            name = "Ansible Play",
            hosts = host_list,
            gather_facts = 'no',
            tasks = [ dict(action=dict(module=module, args=args)) ]
        )
    play = Play().load(play_source, variable_manager=variable_manager, loader=loader)

    # actually run it
    tqm = None
    callback = ResultsCollector()
    try:
        tqm = TaskQueueManager(
                inventory=inventory,
                variable_manager=variable_manager,
                loader=loader,
                options=options,
                passwords=passwords,
            )
        tqm._stdout_callback = callback
        tqm.run(play)
        return callback.results[0]['tasks'][0]['hosts']

    finally:
        if tqm is not None:
            tqm.cleanup()
开发者ID:qwerkinglin,项目名称:CMDB_platform,代码行数:48,代码来源:ansible_project_task.py

示例6: run

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import _stdout_callback [as 别名]
    def run(self):
        self.variable_manager.set_inventory(self.inventory)
        play = Play().load(self.create_play_tasks(),
                           variable_manager=self.variable_manager, loader=self.loader)
        tqm = None
        callback = ResultsCollector()

        tqm = TaskQueueManager(
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            passwords=self.passwords
        )
        tqm._stdout_callback = callback
        result = tqm.run(play)

        return result, callback
开发者ID:fengxsong,项目名称:django-example,代码行数:20,代码来源:ansible_api.py

示例7: run_play

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import _stdout_callback [as 别名]
    def run_play(self, host_list, module_name, module_args):
        """
        run play
        :param host_list is list,
        :param module_name is string
        :param module_args is string
        """
        play = None
        # create play with tasks
        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)
        # actually run it
        tqm = None
        display = LogDisplay(logname=self.job_id)
        callback = CALLBACKMODULE[CALLBACK](display=display)
        if module_name == 'backup':
            # 对于备份模块,特殊处理,必须使用minimal,才能获取到文件名属性
            callback = minimal_callback(display=display)

        try:
            tqm = TaskQueueManager(
                inventory=self.inventory,
                variable_manager=self.variable_manager,
                loader=self.loader,
                options=self.options,
                passwords=self.passwords,
            )
            tqm._stdout_callback = callback
            tqm.run(play)
        finally:
            if tqm is not None:
                tqm.cleanup()

        return display.get_log_json()
开发者ID:AutoOps,项目名称:MagicStack-Proxy,代码行数:41,代码来源:task.py


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