zoukankan      html  css  js  c++  java
  • python执行playbook

     1 from collections import namedtuple
     2 from ansible.parsing.dataloader import DataLoader
     3 from ansible.vars.manager import VariableManager
     4 from ansible.inventory.manager import InventoryManager
     5 from ansible.executor.playbook_executor import PlaybookExecutor
     6 
     7 Options = namedtuple(
     8     'Options',
     9     [
    10         'connection',
    11         'remote_user',
    12         'ask_sudo_pass',
    13         'verbosity',
    14         'ask_pass',
    15         'module_path',
    16         'forks',
    17         'become',
    18         'become_method',
    19         'become_user',
    20         'check',
    21         'listhosts',
    22         'listtasks',
    23         'listtags',
    24         'syntax',
    25         'sudo_user',
    26         'sudo',
    27         'diff'
    28     ]
    29 )
    30 options = Options(
    31     connection='smart',
    32     remote_user=None,
    33     ask_pass=None,
    34     sudo_user=None,
    35     forks=5,
    36     sudo=None,
    37     ask_sudo_pass=False,
    38     verbosity=5,
    39     module_path=None,
    40     become=None,
    41     become_method=None,
    42     become_user=None,
    43     check=False,
    44     diff=False,
    45     listhosts=None,
    46     listtasks=None,
    47     listtags=None,
    48     syntax=None
    49 )
    50 
    51 def run_pb(sources, pb_path):
    52     loader = DataLoader()
    53     passwords = dict()
    54     inventory = InventoryManager(loader=loader, sources=sources)
    55     variable_manager = VariableManager(loader=loader, inventory=inventory)
    56     pb = PlaybookExecutor(
    57         playbooks=pb_path,
    58         inventory=inventory,
    59         variable_manager=variable_manager,
    60         loader=loader,
    61         options=options,
    62         passwords=passwords
    63     )
    64     result = pb.run()
    65     return result
    66 
    67 if __name__ == '__main__':
    68     sources = ['myansible/hosts']
    69     playbook = ['myansible/lamp.yml']
    70     run_pb(sources, playbook)
  • 相关阅读:
    兼容IE的滚动条自定义样式
    vue从入门到开发--4--处理http请求
    vue从入门到开发--3-基础语法
    Oracle 扩容表空间
    Oracle 整库备份还原
    Oracle 相关命令
    更改mysql数据库根目录
    关于文件系统
    挂载iscsi存储
    挂载nfs存储
  • 原文地址:https://www.cnblogs.com/ray-mmss/p/10619146.html
Copyright © 2011-2022 走看看