码迷,mamicode.com
首页 > Windows程序 > 详细

ansible-playbook api

时间:2016-09-09 20:52:12      阅读:390      评论:0      收藏:0      [点我收藏+]

标签:

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()

ansible-playbook api

标签:

原文地址:http://www.cnblogs.com/3one/p/5857889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!