#!/usr/bin/env python
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 #引入executor模块
#用来加载解析yml文件或者json内容
loader = DataLoader() #读取yaml文件
variable_manager = VariableManager()
#根据inventory加载对应变量,此处host_list参数可以有两种格式:
#1: hosts文件(需要),
#2: 可以是IP列表,此处使用IP列表
inventory = Inventory(loader=loader, variable_manager=variable_manager,host_list=’/data/test/ansible_2.3/hosts’) #这里可通过分析源码得到参数
variable_manager.set_inventory(inventory)
passwords=None
#初始化
Options = namedtuple(‘Options’,
[‘connection’,
‘remote_user’,
‘ask_sudo_pass’,
‘verbosity’,
‘ack_pass’,
‘module_path’,
‘forks’,
‘become’,
‘become_method’,
‘become_user’,