当前位置: 首页>>代码示例>>Python>>正文


Python manager.InventoryManager方法代码示例

本文整理汇总了Python中ansible.inventory.manager.InventoryManager方法的典型用法代码示例。如果您正苦于以下问题:Python manager.InventoryManager方法的具体用法?Python manager.InventoryManager怎么用?Python manager.InventoryManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ansible.inventory.manager的用法示例。


在下文中一共展示了manager.InventoryManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_play_prereqs_2_4

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def get_play_prereqs_2_4(self, options):
        loader = DataLoader()

        if self.vault_pass:
            loader.set_vault_secrets([('default', VaultSecret(_bytes=to_bytes(self.vault_pass)))])

        # create the inventory, and filter it based on the subset specified (if any)
        inventory = InventoryManager(loader=loader, sources=options.inventory)

        # create the variable manager, which will be shared throughout
        # the code, ensuring a consistent view of global variables
        try:
            # Ansible 2.8
            variable_manager = VariableManager(loader=loader, inventory=inventory,
                                               version_info=self.version_info(ansible_version))
            variable_manager._extra_vars = self.extra_vars
        except TypeError:
            variable_manager = VariableManager(loader=loader, inventory=inventory)
            variable_manager.extra_vars = self.extra_vars
            variable_manager.options_vars = {'ansible_version': self.version_info(ansible_version)}

        return loader, inventory, variable_manager 
开发者ID:grycap,项目名称:im,代码行数:24,代码来源:ansible_launcher.py

示例2: execute_playbook

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [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

示例3: ansible_part

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [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

示例4: __init__

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def __init__(self, inventory_generator):
        """
        :type inventory_generator: ops.inventory.generator.InventoryGenerator
        """

        self.inventory_generator = inventory_generator
        self.generated_path, self.ssh_config_path = inventory_generator.generate()

        # clean up variables cache for tests
        ansible_vars.VARIABLE_CACHE = dict()
        ansible_vars.HOSTVARS_CACHE = dict()
        ansible_inventory.HOSTS_PATTERNS_CACHE = dict()

        loader = DataLoader()
        loader.set_basedir(self.generated_path)
        self.inventory = InventoryManager(
            loader=loader, sources=[
                self.generated_path])
        self.variable_manager = VariableManager(
            loader=loader, inventory=self.inventory) 
开发者ID:adobe,项目名称:ops-cli,代码行数:22,代码来源:generator.py

示例5: _get_inventory

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def _get_inventory(self, workspace_name=None):
        """Returns Inventory object for the provided workspace.

           Uses active workspace as default.

           :param workspace_name: workspace name to list nodes from.
        """
        workspace = self.get(
            workspace_name) if workspace_name else self.get_active_workspace()

        if workspace is None:
            if workspace_name is None:
                raise exceptions.IRNoActiveWorkspaceFound()
            else:
                raise exceptions.IRWorkspaceMissing(workspace=workspace_name)

        # need to have import here to avoid ansible patching
        from ansible.inventory.manager import InventoryManager
        from ansible.parsing.dataloader import DataLoader

        return InventoryManager(DataLoader(), sources=workspace.inventory) 
开发者ID:redhat-openstack,项目名称:infrared,代码行数:23,代码来源:workspaces.py

示例6: AnsibleExecApi29

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def AnsibleExecApi29(task_id, tasks=[], inventory_data=None):
    options = get_default_options()
    context.CLIARGS = ImmutableDict(options)

    loader = DataLoader()
    passwords = dict(vault_pass='secret')
    results_callback = RedisCallBack(task_id)
    # inventory = InventoryManager(loader=loader, sources='localhost,')
    if inventory_data:
        inventory = BaseInventory(inventory_data)
    else:
        inventory = BaseInventory(InventoryInit().get_data())
    variable_manager = VariableManager(loader=loader, inventory=inventory)
    play_source =  dict(
            name="Ansible Play",
            hosts='localhost',
            gather_facts='no',
            tasks=tasks,
        )
    play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
    tqm = None
    try:
        tqm = MyTaskQueueManager(
                inventory=inventory,
                variable_manager=variable_manager,
                loader=loader,
                passwords=passwords,
                stdout_callback=results_callback,
            )
        result = tqm.run(play)
    finally:
        if tqm is not None:
            tqm.cleanup()

        shutil.rmtree(C.DEFAULT_LOCAL_TMP, True)


# Ansible 2.9 版本的 vars/manager.py: VariableManager 未有 extra_vars.setter 
开发者ID:lotus-dgas,项目名称:AnsibleUI,代码行数:40,代码来源:AnsibleApi_v29.py

示例7: parse_inventory

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def parse_inventory(inventory):
    loader = DataLoader()
    inv = InventoryManager(loader=loader, sources=[inventory])
    vars = VariableManager(loader=loader, inventory=inv)
    all_groups = inv.get_groups_dict()
    tidb_nodes = all_groups['tidb_servers']
    tikv_nodes = all_groups['tikv_servers']
    tidb_servers = {}
    tikv_servers = {}
    for tidb in tidb_nodes:
        var = vars.get_vars(host=inv.get_host(hostname=str(tidb)))
        ip = var['ansible_host'] if 'ansible_host' in var else var['inventory_hostname']
        tidb_port = var.get('tidb_port', 4000)
        tidb_status_port = var.get('tidb_status_port', 10080)
        deploy_dir = var['deploy_dir']

        if ip in tidb_servers:
            tidb_servers[ip].append([tidb_port, tidb_status_port, deploy_dir])
        else:
            tidb_servers[ip] = [[tidb_port, tidb_status_port, deploy_dir]]

    for tikv in tikv_nodes:
        var = vars.get_vars(host=inv.get_host(hostname=str(tikv)))
        ip = var['ansible_host'] if 'ansible_host' in var else var['inventory_hostname']
        tikv_port = var.get('tikv_port', 20160)
        tikv_status_port = var.get('tikv_status_port', 20180)
        deploy_dir = var['deploy_dir']

        if ip in tikv_servers:
            tikv_servers[ip].append([tikv_port, tikv_status_port, deploy_dir])
        else:
            tikv_servers[ip] = [[tikv_port, tikv_status_port, deploy_dir]]

    return [tidb_servers, tikv_servers] 
开发者ID:pingcap,项目名称:tidb-ansible,代码行数:36,代码来源:inventory_check.py

示例8: inventory_manager

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def inventory_manager(self):
        return InventoryManager(
            loader=self._ansible_inventory_data_loader,
            sources=self.paths.inventory_source
        ) 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:7,代码来源:main.py

示例9: make_inventory

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def make_inventory(self, group):
        self.loader = DataLoader()
        self.inventory = InventoryManager(loader=DataLoader(),)
        self.inventory.add_group(str(group.uuid))
        for host in group.hosts.all():
            self.inventory.add_host(host.connect_ip, str(group.uuid), host.sshport) 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:8,代码来源:playbook.py

示例10: parse_inventory

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def parse_inventory(path):
    inventory = InventoryManager(loader=DataLoader(), sources=path)
    return inventory.get_groups_dict() 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:5,代码来源:cluster.py

示例11: __init__

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def __init__(self, sources='/etc/ansible/hosts'):
        self.sources = sources
        self.variable_manager = None
        self.loader = None
        self.options = None
        self.passwords = None
        self.callback = ResultCallback()
        self.results_raw = {}
        Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'timeout', 'remote_user',
                                         'ask_pass', 'private_key_file', 'ssh_common_args', 'ssh_extra_args',
                                         'sftp_extra_args',
                                         'scp_extra_args', 'become', 'become_method', 'become_user', 'ask_value_pass',
                                         'verbosity',
                                         'check', 'listhosts', 'listtasks', 'listtags', 'syntax', 'diff'])
        self.options = Options(connection='smart', module_path=None, forks=100, timeout=10,
                               remote_user='root', ask_pass=False, 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='root', ask_value_pass=False, verbosity=None, check=False, listhosts=False,
                               listtasks=False, listtags=False, syntax=False, diff=False)

        self.loader = DataLoader()
        self.passwords = dict(vault_pass='secret')
        self.inventory = InventoryManager(self.loader, self.sources)
        # 把inventory传递给variable_manager管理
        self.variable_manager = VariableManager(loader=self.loader, inventory=self.inventory) 
开发者ID:JiaJunZz,项目名称:swallow,代码行数:28,代码来源:ansible_api.py

示例12: initialize_inventory

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def initialize_inventory(self):
        log.debug("HostManagerV28.initialize_inventory()")
        self.options['loader'] = DataLoader()
        self.options['inventory_manager'] = InventoryManager(loader=self.options['loader'],
                                                             sources=self.options['inventory'])
        self.options['variable_manager'] = VariableManager(loader=self.options['loader'],
                                                           inventory=self.options['inventory_manager'])
        # self.options['inventory_manager'].clear_caches() 
开发者ID:ansible,项目名称:pytest-ansible,代码行数:10,代码来源:v28.py

示例13: initialize_inventory

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def initialize_inventory(self):
        log.debug("HostManagerV25.initialize_inventory()")
        self.options['loader'] = DataLoader()
        self.options['inventory_manager'] = InventoryManager(loader=self.options['loader'],
                                                             sources=self.options['inventory'])
        self.options['variable_manager'] = VariableManager(loader=self.options['loader'],
                                                           inventory=self.options['inventory_manager'])
        # self.options['inventory_manager'].clear_caches() 
开发者ID:ansible,项目名称:pytest-ansible,代码行数:10,代码来源:v25.py

示例14: initialize_inventory

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def initialize_inventory(self):
        log.debug("HostManagerV24.initialize_inventory()")
        self.options['loader'] = DataLoader()
        self.options['inventory_manager'] = InventoryManager(loader=self.options['loader'],
                                                             sources=self.options['inventory'])
        self.options['variable_manager'] = VariableManager(loader=self.options['loader'],
                                                           inventory=self.options['inventory_manager'])
        # self.options['inventory_manager'].clear_caches() 
开发者ID:ansible,项目名称:pytest-ansible,代码行数:10,代码来源:v24.py

示例15: __init__

# 需要导入模块: from ansible.inventory import manager [as 别名]
# 或者: from ansible.inventory.manager import InventoryManager [as 别名]
def __init__(self,resource,loader,variable_manager):
        self.resource = resource
        self.loader = DataLoader()
        self.inventory = InventoryManager(loader=self.loader, sources=['%s/conf/hostslist'%BASE_DIR])
        # self.variable_manager.set_inventory(self.inventory)
        self.variable_manager = VariableManager(loader=self.loader, inventory=self.inventory)
        self.dynamic_inventory() 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:9,代码来源:ansible_api.py


注:本文中的ansible.inventory.manager.InventoryManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。