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


Python TaskQueueManager.cleanup方法代码示例

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


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

示例1: ansible_adhoc

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
def ansible_adhoc(ips):
    logger.info("ansible需要采集%d个IP" % (len(ips)))
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=ips)
    # 根据 inventory 加载对应变量
    variable_manager.set_inventory(inventory)
    # 增加外部变量
    variable_manager.extra_vars = {"ansible_ssh_user": ansible_username, "ansible_ssh_pass": ansible_password}
    play_source = {"name": "Ansible Ad-Hoc", "hosts": ips, "gather_facts": "no",
                   "tasks": [{"action": {"module": "setup", "args": ""}}]}
    play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
    tqm = None
    try:
        tqm = TaskQueueManager(
            inventory=inventory,
            variable_manager=variable_manager,
            loader=loader,
            options=options,
            passwords=None,
            stdout_callback=resultcallback,
            run_tree=False,
        )
        tqm.run(play)
        return ansible_facts_info
    finally:
        if tqm is not None:
            tqm.cleanup()
开发者ID:fwyy0315,项目名称:AutoDiscovery,代码行数:28,代码来源:ansible_api.py

示例2: run_adhoc

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
def run_adhoc():
    variable_manager.extra_vars = {
        "ansible_ssh_user": "root", "ansible_ssh_pass": "Xinao.com123123"
    }  # 增加外部变量
    # 构建pb, 这里很有意思, 新版本运行ad-hoc或playbook都需要构建这样的pb, 只是最后调用play的类不一样
    # :param name: 任务名,类似playbook中tasks中的name
    # :param hosts: playbook中的hosts
    # :param tasks: playbook中的tasks, 其实这就是playbook的语法, 因为tasks的值是个列表,因此可以写入多个task
    play_source = {
        "name": "Ansible Ad-Hoc",
        "hosts": "localhost",
        "gather_facts": "no",
        "tasks": [
            {"action": {"module": "shell", "args": "w"}}
        ]
    }
    play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
    tqm = None
    try:
        tqm = TaskQueueManager(
            inventory=inventory,
            variable_manager=variable_manager,
            loader=loader,
            options=options,
            passwords=None,
            stdout_callback='minimal',
            run_tree=False,
        )
        result = tqm.run(play)
        print result
    finally:
        if tqm is not None:
            tqm.cleanup()
开发者ID:sunyaxiong,项目名称:mygit,代码行数:35,代码来源:ans2_coocla.py

示例3: my_runner

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
def my_runner(host_list,module_name,module_args):
 variable_manager.extra_vars={} # 增加外部变量
 # 构建pb, 这里很有意思, 新版本运行ad-hoc或playbook都需要构建这样的pb, 只是最后调用play的类不一样
 # :param name: 任务名,类似playbook中tasks中的name
 # :param hosts: playbook中的hosts
 # :param tasks: playbook中的tasks, 其实这就是playbook的语法, 因为tasks的值是个列表,因此可以写入多个task
 play_source = {"name":"Ansible Ad-Hoc","hosts":host_list,"gather_facts":"no","tasks":[{"action":{"module":module_name,"args":module_args}}]}
 play = Play().load(play_source,variable_manager=variable_manager,loader=loader)
 tqm = None
# results_callback = call_json.CallbackModule()
 try:
   tqm = TaskQueueManager(
	inventory=inventory,
 	variable_manager=variable_manager,
 	loader=loader,
 	options=options,
 	passwords=None,
 	stdout_callback='minimal',
#	stdout_callback=results_callback,  # Use our custom callback instead of the ``default`` callback plugin
   )
   savedStdout = sys.stdout
   with open(File_PATH,'w+') as file:
     sys.stdout = file #标准输出重定向至文件
     result = tqm.run(play)
   sys.stdout = savedStdout  
   return result
 
 finally:
   if tqm is not None:
     tqm.cleanup()
开发者ID:McCoyZ,项目名称:PyLearning,代码行数:32,代码来源:job.py

示例4: run

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
    def run(self, play_data):
        """
        paly_data = dict(
            name="Ansible Ad-Hoc",
            hosts=pattern,
            gather_facts=True,
            tasks=[dict(action=dict(module='service', args={'name': 'vsftpd', 'state': 'restarted'}), async=async, poll=poll)]
        )
        """
        self._prepare_run()

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

        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.cb,
                run_additional_callbacks=C.DEFAULT_LOAD_CALLBACK_PLUGINS,
                run_tree=False,
            )

            result = tqm.run(play)
            return result
        finally:
            if tqm:
                tqm.cleanup()
开发者ID:sunyaxiong,项目名称:mygit,代码行数:33,代码来源:ans_ui2_share.py

示例5: run_module

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
    def run_module(self, hosts, module_name, module_args):
        # create play with tasks
        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)

        self.results_callback = ModuleResultCallback()
        # 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.
                results_callback,  # Use our custom callback instead of the ``default`` callback plugin
            )
            result = tqm.run(play)
        finally:
            if tqm is not None:
                tqm.cleanup()
开发者ID:boer0924,项目名称:deploy,代码行数:31,代码来源:remoteshell.py

示例6: run

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [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

示例7: run_model

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [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

示例8: run

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
    def run(self):

        # create play with tasks
        play_source =  dict(
                name = "Ansible Play",
                hosts = self.host_list,
                #hosts = 'localhost',
                gather_facts = 'no',
                tasks = [
                    dict(action=dict(module='shell', args='ls')),
                    #dict(action=dict(module='shell', args='ls'), register='shell_out'),
                    #dict(action=dict(module='debug', args=dict(msg='{{shell_out.stdout}}')))
                 ]
            )
        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.results_callback,  # Use our custom callback instead of the ``default`` callback plugin
                  )
            result = tqm.run(play)
        finally:
            if tqm is not None:
                tqm.cleanup()
开发者ID:xiaoxuanzi,项目名称:HistCode,代码行数:33,代码来源:test_ansible.py

示例9: run_model

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [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

示例10: run_module

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
 def run_module(self, hosts='localhost', rules=[{'module': 'setup'}]):
     '''
     rules=[
           {'module': 'shell', 'args': 'echo "ok"', 'register': 'echo_ok'},
           {'module': 'debug', 'args': {'msg': '{{echo_ok.stdout}}'}}
     ]
     '''
     tasks = []
     for rule in rules:
         if 'register' in rule:
             register = rule.pop('register')
         tasks.append(dict(dict(action=rule), register=register))
     play_source =  dict(
         name = "Ansible Play",
         hosts = hosts,
         gather_facts = 'no',
         tasks = tasks
     )
     results_callback = ResultCallback()
     play = Play().load(play_source, variable_manager=self.variable_manager, loader=self.loader)
     qm = None
     try:
         tqm = TaskQueueManager(
               inventory=self.inventory,
               variable_manager=self.variable_manager,
               loader=self.loader,
               options=self.options,
               passwords=self.passwords,
               stdout_callback=results_callback,
          )
         tqm.run(play)
         return results_callback
     finally:
         if tqm is not None:
             tqm.cleanup()
开发者ID:stanleylst,项目名称:ansibleUI,代码行数:37,代码来源:Ansi_play2.py

示例11: test_strategy_base_run_handlers

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
    def test_strategy_base_run_handlers(self, mock_worker):
        def fake_run(*args):
            return
        mock_worker.side_effect = fake_run
        mock_play_context = MagicMock()

        mock_handler_task = MagicMock(Handler)
        mock_handler_task.action = 'foo'
        mock_handler_task.get_name.return_value = "test handler"
        mock_handler_task.has_triggered.return_value = False

        mock_handler = MagicMock()
        mock_handler.block = [mock_handler_task]
        mock_handler.flag_for_host.return_value = False

        mock_play = MagicMock()
        mock_play.handlers = [mock_handler]

        mock_host = MagicMock(Host)
        mock_host.name = "test01"
        mock_host.has_hostkey = True

        mock_inventory = MagicMock()
        mock_inventory.get_hosts.return_value = [mock_host]

        mock_var_mgr = MagicMock()
        mock_var_mgr.get_vars.return_value = dict()

        mock_iterator = MagicMock
        mock_iterator._play = mock_play

        fake_loader = DictDataLoader()
        mock_options = MagicMock()
        mock_options.module_path = None

        tqm = TaskQueueManager(
            inventory=mock_inventory,
            variable_manager=mock_var_mgr,
            loader=fake_loader,
            options=mock_options,
            passwords=None,
        )
        tqm._initialize_processes(3)
        tqm._initialize_notified_handlers(mock_play)
        tqm.hostvars = dict()

        try:
            strategy_base = StrategyBase(tqm=tqm)

            strategy_base._inventory = mock_inventory
            strategy_base._notified_handlers = {mock_handler_task: [mock_host]}

            task_result = TaskResult(Host('host01'), Handler(), dict(changed=False))
            tqm._final_q.put(('host_task_ok', task_result))

            result = strategy_base.run_handlers(iterator=mock_iterator, play_context=mock_play_context)
        finally:
            tqm.cleanup()
开发者ID:LukeInkster,项目名称:PythonCorpus,代码行数:60,代码来源:test_strategy_base.py

示例12: main

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [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

示例13: main

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
def main(args):
    # Options definition
    # Custom tuple to store playbook options
    Options = namedtuple('Options', ['connection', 'module_path', 'forks',
                                     'become', 'become_method', 'become_user',
                                     'check'])

    # Object initialization
    variable_manager = VariableManager()
    loader = DataLoader()
    options = Options(connection='ssh',module_path='library',
                      forks=100, become=None, become_method=None,
                      become_user=None, check=False)
    passwords = {}

    # Dinamyc inventory
    inventory = Inventory(loader=loader, variable_manager=variable_manager,
                          host_list=args)

    # Inventory assignation
    variable_manager.set_inventory(inventory)

    # Play creation with tasks
    play_source = dict(
         name="Ansible Play",
         hosts=args,
         gather_facts='no',
         tasks=[
             dict(action=dict(module='shell', args='hostname -f'),
                  register='shell_out'),
             dict(action=dict(module='debug',
                              args=dict(msg='{{shell_out.stdout}}')))
         ]
    )

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

    # Running it
    tqm = None
    try:
        tqm = TaskQueueManager(
                      inventory=inventory,
                      variable_manager=variable_manager,
                      loader=loader,
                      options=options,
                      passwords=passwords,
                      stdout_callback='default'
        )
        result = tqm.run(play)
    finally:
        if tqm is not None:
                    tqm.cleanup()
开发者ID:jadebustos,项目名称:ansible,代码行数:55,代码来源:ansible2.x-example.py

示例14: main

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
def main(argv=sys.argv[1:]):
    Options = namedtuple('Options', ['connection', 'module_path', 'forks',
                                     'become', 'become_method', 'become_user',
                                     'check'])
    # initialize needed objects
    variable_manager = VariableManager()
    loader = DataLoader()
    options = Options(connection='local', module_path='/path/to/mymodules',
                      forks=100, become=None, become_method=None,
                      become_user=None,
                      check=False)

    passwords = dict(vault_pass='secret')

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

    variable_manager.set_inventory(inventory)

    # create play with tasks
    play_source = dict(name="Ansible Play",
                       hosts='localhost',
                       gather_facts='no',
                       tasks=[
                           dict(action=dict(module='shell',
                                args='uname -a'), register='shell_out'),
                           dict(action=dict(module='debug',
                                args=dict(msg='{{shell_out.stdout}}')))
                       ]
                       )

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

    # actually run it
    tqm = None
    try:
        tqm = TaskQueueManager(inventory=inventory,
                               variable_manager=variable_manager,
                               loader=loader,
                               options=options,
                               passwords=passwords,
                               stdout_callback='default',
                               )

        result = tqm.run(play)
        print result
    finally:
        if tqm is not None:
            tqm.cleanup()
开发者ID:javiroman,项目名称:foreman-op,代码行数:53,代码来源:embedded-uname.py

示例15: test_base

# 需要导入模块: from ansible.executor.task_queue_manager import TaskQueueManager [as 别名]
# 或者: from ansible.executor.task_queue_manager.TaskQueueManager import cleanup [as 别名]
    def test_base(self):
        test_inv_dir = 'test/inventory'
        for inv in os.listdir(test_inv_dir):
            print "Processing ", inv
            res = dynlxc.main(os.path.join(test_inv_dir, inv), '')

            variable_manager = VariableManager()
            loader = DataLoader()
            self.mock_rv.communicate.return_value = [
                json.dumps(res), 'mocked_err']
            try:
                inventory = Inventory(
                    loader=loader,
                    variable_manager=variable_manager,
                    host_list='inventory/dynlxc.py'
                )
            except Exception as err:
                raise Exception("Inventory file {0} processing result '{1}' "
                                "failed with {2}".format(inv, res, err))
            variable_manager.set_inventory(inventory)

            play_source = dict(name="Ansible Play", hosts='localhost',
                               gather_facts='no')

            playbook = os.path.abspath(os.path.join(test_inv_dir,
                                       '../playbooks', inv))
            if os.path.isfile(playbook):
                with open(playbook) as fh:
                    real_playbook = yaml.load(fh)[0]
                    play_source.update(real_playbook)

            play = Play().load(play_source, variable_manager=variable_manager,
                               loader=loader)
            tqm = None
            try:
                tqm = TaskQueueManager(
                    inventory=inventory,
                    variable_manager=variable_manager,
                    loader=loader,
                    options=self.options,
                    passwords=None,
                    stdout_callback='default',
                )
                result = tqm.run(play)
                assert result == 0, ("Ansible playbook exitcode "
                                     "different from 0")
            finally:
                if tqm is not None:
                    tqm.cleanup()
开发者ID:devjatkin,项目名称:stackforce-ansible,代码行数:51,代码来源:tests_dynlxc.py


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