當前位置: 首頁>>代碼示例>>Python>>正文


Python playbook_executor.PlaybookExecutor方法代碼示例

本文整理匯總了Python中ansible.executor.playbook_executor.PlaybookExecutor方法的典型用法代碼示例。如果您正苦於以下問題:Python playbook_executor.PlaybookExecutor方法的具體用法?Python playbook_executor.PlaybookExecutor怎麽用?Python playbook_executor.PlaybookExecutor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ansible.executor.playbook_executor的用法示例。


在下文中一共展示了playbook_executor.PlaybookExecutor方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def run(self, playbook_path, extra_vars=None, **kwargs):
        C.DEFAULT_ROLES_PATH = self.options.roles_path
        if extra_vars and isinstance(extra_vars, dict):
            self.variable_manager.extra_vars = extra_vars
        executor = PlaybookExecutor(
            playbooks=[playbook_path],
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            passwords=self.options.passwords
        )

        if executor._tqm:
            executor._tqm._stdout_callback = self.results_callback

        try:
            executor.run()
            return self.results_callback.results
        except AnsibleError:
            executor._tqm.cleanup()
            self.loader.cleanup_all_tmp_files() 
開發者ID:KubeOperator,項目名稱:KubeOperator,代碼行數:24,代碼來源:runner.py

示例2: run

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def run(self):
        executor = PlaybookExecutor(
            playbooks=[self.playbook_path],
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            passwords=self.passwords
        )

        if executor._tqm:
            executor._tqm._stdout_callback = self.results_callback
        executor.run()
        executor._tqm.cleanup()
        try:
            results_callback = self.results_callback.output['plays'][0]['tasks'][1]['hosts']
            status = self.results_callback.output['stats']
            results = {"results_callback": results_callback, "status": status}
            return results
        except Exception as e:

            raise AnsibleError(
                'The hostname parameter or groups parameter in the BaseInventory \
                               does not match the hosts parameter in the yaml file.{}'.format(e)) 
開發者ID:hequan2017,項目名稱:chain,代碼行數:26,代碼來源:runner.py

示例3: execute_playbook

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def execute_playbook():
    playbook_path = "playbook_template.yml"
    inventory_path = "hosts"

    Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'become', 'become_method', 'become_user', 'check', 'diff', 'listhosts', 'listtasks', 'listtags', 'syntax'])
    loader = DataLoader()
    options = Options(connection='local', module_path='', forks=100, become=None, become_method=None, become_user=None, check=False,
                    diff=False, listhosts=False, listtasks=False, listtags=False, syntax=False)
    passwords = dict(vault_pass='secret')

    inventory = InventoryManager(loader=loader, sources=['inventory'])
    variable_manager = VariableManager(loader=loader, inventory=inventory)
    executor = PlaybookExecutor(  
                playbooks=[playbook_path], inventory=inventory, variable_manager=variable_manager, loader=loader,  
                options=options, passwords=passwords)  
    results = executor.run()  
    print results 
開發者ID:PacktPublishing,項目名稱:Learning-Python-Networking-Second-Edition,代碼行數:19,代碼來源:execute_playbook.py

示例4: ansible_part

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def ansible_part():
    playbook_path = "checktemplate.yml"
    inventory_path = "hosts"

    Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'become', 'become_method', 'become_user', 'check', 'diff', 'listhosts', 'listtasks', 'listtags', 'syntax'])
    loader = DataLoader()
    options = Options(connection='local', module_path='', forks=100, become=None, become_method=None, become_user=None, check=False,
                    diff=False, listhosts=False, listtasks=False, listtags=False, syntax=False)
    passwords = dict(vault_pass='secret')

    inventory = InventoryManager(loader=loader, sources=['inventory'])
    variable_manager = VariableManager(loader=loader, inventory=inventory)
    executor = PlaybookExecutor(  
                playbooks=[playbook_path], inventory=inventory, variable_manager=variable_manager, loader=loader,  
                options=options, passwords=passwords)  
    results = executor.run()  
    print results 
開發者ID:PacktPublishing,項目名稱:Practical-Network-Automation-Second-Edition,代碼行數:19,代碼來源:checkpython.py

示例5: run_playbook

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def run_playbook(self, playbook_path,extra_vars=None):
        """
        run ansible palybook
        """
        try:
            # if self.redisKey:self.callback = PlayBookResultsCollectorToSave(self.redisKey,self.logId)
            self.callback = PlayBookResultsCollector()
            if extra_vars:self.variable_manager.extra_vars = extra_vars
            executor = PlaybookExecutor(
                playbooks=[playbook_path], inventory=self.inventory, variable_manager=self.variable_manager, loader=self.loader,
                options=self.options, passwords=self.passwords,
            )
            executor._tqm._stdout_callback = self.callback
            constants.HOST_KEY_CHECKING = False #關閉第一次使用ansible連接客戶端是輸入命令
            executor.run()
        except Exception as err:
            return False 
開發者ID:iopsgroup,項目名稱:imoocc,代碼行數:19,代碼來源:ansible_api.py

示例6: run

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def run(self):
            executor = PlaybookExecutor(
                playbooks=[self.playbook_path],
                inventory=self.inventory,
                variable_manager=self.variable_manager,
                loader=self.loader,
                options=self.options,
                passwords=self.passwords
            )

            if executor._tqm:
                executor._tqm._stdout_callback = self.results_callback
            executor.run()
            executor._tqm.cleanup()
            try:
                results_callback=self.results_callback.output['plays'][0]['tasks'][1]['hosts']
                status=self.results_callback.output['stats']
                results={"results_callback":results_callback,"status":status}
                return results
            except Exception as e:
                raise AnsibleError('The hostname parameter or groups parameter in the BaseInventory \
                                   does not match the hosts parameter in the yaml file.') 
開發者ID:hequan2017,項目名稱:autoops,代碼行數:24,代碼來源:runner.py

示例7: run

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def run(self, verbose=False):
        if not verbose:
            # Results of PlaybookExecutor
            cb = DisplayErrorCallback()
            self.pbex._tqm._stdout_callback = cb
        try:
            res = self.pbex.run()
        except AnsibleParserError as err:
            print(err)
            return None
        stats = self.pbex._tqm._stats

        # Test if success for record_logs
        run_success = True
        hosts = sorted(stats.processed.keys())
        for h in hosts:
            t = stats.summarize(h)
            if t['unreachable'] > 0 or t['failures'] > 0:
                run_success = False

        return stats 
開發者ID:Juniper,項目名稱:contrail-docker,代碼行數:23,代碼來源:runner.py

示例8: load_callbacks

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def load_callbacks(self):   # 為callback 設置存儲id
        pass

# 重新封裝 PlaybookExecutor , 傳入 task_id 
開發者ID:lotus-dgas,項目名稱:AnsibleUI,代碼行數:6,代碼來源:AnsibleApi_v29.py

示例9: __init__

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def __init__(self, host_list, playbook_path, private_key_file="/root/.ssh/id_rsa", forks=5, extra_vars=None):
        super(AnsiblePlayTask, self).__init__(host_list, private_key_file, forks, extra_vars)
        passwords = {}
        self.call_back = result_collector.CallbackModule()
        self.pbex = PlaybookExecutor(playbooks=[playbook_path],
                                     inventory=self.inventory,
                                     variable_manager=self.variable_manager,
                                     loader=self.loader,
                                     options=self.options,
                                     passwords=passwords)
        self.pbex._tqm._stdout_callback = self.call_back 
開發者ID:510908220,項目名稱:heartbeats,代碼行數:13,代碼來源:ansible_task.py

示例10: setup

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def setup(self, pb_file):

        self.pb_file = pb_file
        self.playbook = PlaybookExecutor(playbooks=[self.pb_file],
                                         inventory=self.inventory,
                                         variable_manager=self.variable_manager,
                                         loader=self.loader,
                                         options=self.options,
                                         passwords={}) 
開發者ID:pcuzner,項目名稱:ceph-ansible-copilot,代碼行數:11,代碼來源:playbook.py

示例11: __init__

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def __init__(self, playbook, inventory, run_data=None, verbosity=0, tags=None, skip_tags=None):
        self.run_data = run_data or {}
        self.options = Options()

        self.options.verbosity = verbosity
        self.options.connection = 'local'  # Need a connection type "smart" or "ssh"
        self.options.become = True
        self.options.become_method = 'sudo'
        self.options.become_user = 'root'
        self.options.tags = tags or []
        self.options.skip_tags = skip_tags or []
        # Set global verbosity
        self.display = Display()
        self.display.verbosity = self.options.verbosity
        # Executor appears to have it's own
        # verbosity object/setting as well
        playbook_executor.verbosity = self.options.verbosity

        # Become Pass Needed if not logging in as user root
        passwords = {}

        # Gets data from YAML/JSON files
        self.loader = DataLoader()
        self.loader.set_vault_password(os.environ.get('VAULT_PASS',''))

        # All the variables from all the various places
        self.variable_manager = VariableManager()
        self.variable_manager.extra_vars = self.run_data

        self.inventory = Inventory(loader=self.loader, variable_manager=self.variable_manager, host_list=inventory)
        self.variable_manager.set_inventory(self.inventory)

        # Setup playbook executor, but don't run until run() called
        self.pbex = playbook_executor.PlaybookExecutor(
            playbooks=[playbook],
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            passwords=passwords) 
開發者ID:Juniper,項目名稱:contrail-docker,代碼行數:42,代碼來源:runner.py

示例12: __init__

# 需要導入模塊: from ansible.executor import playbook_executor [as 別名]
# 或者: from ansible.executor.playbook_executor import PlaybookExecutor [as 別名]
def __init__(self, playbook, hosts='hosts', options={}, passwords={}, vault_pass=None):

        # Set options
        self.options = Options()
        for k, v in options.iteritems():
            setattr(self.options, k, v)

        # Set global verbosity
        self.display = display
        self.display.verbosity = self.options.verbosity

        # Executor has its own verbosity setting
        playbook_executor.verbosity = self.options.verbosity

        # Gets data from YAML/JSON files
        self.loader = DataLoader()
        # Set vault password
        if vault_pass is not None:
            self.loader.set_vault_password(vault_pass)
        elif 'VAULT_PASS' in os.environ:
            self.loader.set_vault_password(os.environ['VAULT_PASS'])

        # All the variables from all the various places
        self.variable_manager = VariableManager()
        if self.options.python_interpreter is not None:
            self.variable_manager.extra_vars = {
                'ansible_python_interpreter': self.options.python_interpreter
            }

        # Set inventory, using most of above objects
        self.inventory = Inventory( loader=self.loader, 
                                    variable_manager=self.variable_manager,
                                    host_list=hosts)

        if len(self.inventory.list_hosts()) == 0:
            # Empty inventory
            self.display.error("Provided hosts list is empty.")
            sys.exit(1)

        self.inventory.subset(self.options.subset)

        if len(self.inventory.list_hosts()) == 0:
            # Invalid limit
            self.display.error("Specified limit does not match any hosts.")
            sys.exit(1)

        self.variable_manager.set_inventory(self.inventory)

        # Setup playbook executor, but don't run until run() called
        self.pbex = playbook_executor.PlaybookExecutor(
            playbooks=[playbook],
            inventory=self.inventory,
            variable_manager=self.variable_manager,
            loader=self.loader,
            options=self.options,
            passwords=passwords) 
開發者ID:wagoodman,項目名稱:bridgy,代碼行數:58,代碼來源:ansible_utils.py


注:本文中的ansible.executor.playbook_executor.PlaybookExecutor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。