zoukankan      html  css  js  c++  java
  • ansible-playbook api

    import os
    import sys
    import ansible
    from collections import namedtuple

    from ansible.parsing.dataloader import DataLoader
    from ansible.vars import VariableManager
    from ansible.inventory import Inventory
    from ansible.executor.playbook_executor import PlaybookExecutor

    def playbook_action(playbook, hosts):
    variable_manager = VariableManager()
    loader = DataLoader()
    inventory = ansible.inventory.Inventory(loader=loader,variable_manager=variable_manager)
    inventory.clear_pattern_cache()
    Options = namedtuple('Options', ['listtags', 'listtasks', 'listhosts', 'syntax', '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'])
    options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='ssh', module_path=None, 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)
    variable_manager.extra_vars = {'host': hosts}
    passwords = {}
    pbex = PlaybookExecutor(playbooks=[playbook], inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords)
    pbex.run()
  • 相关阅读:
    数据库中随机返回n条数据的方法
    sql中NULL之恨
    数据库性能的查询优化特刊待续
    sql中exists替换in的区别
    代码的效率问题看一下代码
    检测数据库性能的方法
    Linux随堂1
    设置网页的图标
    C# 线程、timer例句
    转:1.2 Oracle表空间的操作
  • 原文地址:https://www.cnblogs.com/3one/p/5857889.html
Copyright © 2011-2022 走看看