當前位置: 首頁>>代碼示例>>Python>>正文


Python manager.VariableManager方法代碼示例

本文整理匯總了Python中ansible.vars.manager.VariableManager方法的典型用法代碼示例。如果您正苦於以下問題:Python manager.VariableManager方法的具體用法?Python manager.VariableManager怎麽用?Python manager.VariableManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ansible.vars.manager的用法示例。


在下文中一共展示了manager.VariableManager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_play_prereqs_2

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def get_play_prereqs_2(self, options):
        loader = DataLoader()

        if self.vault_pass:
            loader.set_vault_password(self.vault_pass)

        variable_manager = VariableManager()
        variable_manager.extra_vars = self.extra_vars
        variable_manager.options_vars = {'ansible_version': self.version_info(ansible_version)}

        inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=options.inventory)
        variable_manager.set_inventory(inventory)

        # let inventory know which playbooks are using so it can know the
        # basedirs
        inventory.set_playbook_basedir(os.path.dirname(self.playbook_file))

        return loader, inventory, variable_manager 
開發者ID:grycap,項目名稱:im,代碼行數:20,代碼來源:ansible_launcher.py

示例2: get_play_prereqs_2_4

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [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

示例3: execute_playbook

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [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

示例4: ansible_part

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [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

示例5: __init__

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [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

示例6: get

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def get(self):
        data_loader = DataLoader()
        # data_loader.set_vault_password()
        variable_manager = VariableManager(loader=data_loader)

        extra_vars = self.console_args.extra_vars[:]

        extra_vars.append(
            'cluster=' +
            get_cluster_name(
                self.cluster_config_path))

        options = collections.namedtuple('options', 'extra_vars')
        variable_manager.extra_vars = load_extra_vars(
            loader=data_loader, options=options(extra_vars=extra_vars))

        variables = variable_manager.get_vars()

        rendered = self.template.render(self.cluster_config_path, variables)

        return yaml.safe_load(rendered) 
開發者ID:adobe,項目名稱:ops-cli,代碼行數:23,代碼來源:config.py

示例7: __initializeData

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def __initializeData(self):
        """ 初始化ansible """
        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.loader = DataLoader()
        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=True)

        self.passwords = dict(sshpass=None, becomepass=None)
        myinvent = MyInventory(self.resource, self.loader, self.variable_manager)
        self.inventory = myinvent.inventory
        self.variable_manager = myinvent.variable_manager

        # self.variable_manager.set_inventory(self.inventory)
        # self.variable_manager = VariableManager(loader=self.loader, inventory=self.inventory) 
開發者ID:iopsgroup,項目名稱:imoocc,代碼行數:23,代碼來源:ansible_api.py

示例8: AnsibleExecApi29

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [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

示例9: __init__

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def __init__(self, inventory, options=None):
        self.options = self.get_options(options)
        self.inventory = inventory
        self.loader = DataLoader()
        self.variable_manager = VariableManager(
            loader=self.loader, inventory=self.inventory
        )
        self.set_result_callback() 
開發者ID:KubeOperator,項目名稱:KubeOperator,代碼行數:10,代碼來源:runner.py

示例10: __init__

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def __init__(self, inventory, options=None):
        if options:
            self.options = options
        self.inventory = inventory
        self.loader = DataLoader()
        self.variable_manager = VariableManager(
            loader=self.loader, inventory=self.inventory
        ) 
開發者ID:hequan2017,項目名稱:chain,代碼行數:10,代碼來源:runner.py

示例11: parse_inventory

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [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

示例12: get_variable_manager

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def get_variable_manager(data_loader, inventory_manager):
    return VariableManager(data_loader, inventory_manager) 
開發者ID:dimagi,項目名稱:commcare-cloud,代碼行數:4,代碼來源:main.py

示例13: __init__

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def __init__(self, inventory, ask_vault_pass, vault_password_files, vault_ids):
        from ansible.cli import CLI
        super(AnsibleInventory, self).__init__()
        loader = DataLoader()
        if vault_ids or vault_password_files or ask_vault_pass:
            CLI.setup_vault_secrets(loader, vault_ids, vault_password_files, ask_vault_pass)
        self.inventory = ansible.inventory.manager.InventoryManager(loader=loader,
                                                                    sources=inventory)
        self.variable_manager = VariableManager(loader=loader)
        self.variable_manager.set_inventory(self.inventory)

    # internal fuctions that actually do the work
    # adapted almost entirely from lib/ansible/vars/manager.py 
開發者ID:willthames,項目名稱:ansible-inventory-grapher,代碼行數:15,代碼來源:inventory.py

示例14: __init__

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [as 別名]
def __init__(self, group, key, callback):
        self.options = Options(
            connection='smart', module_path='', forks=100, become=None,
            become_method=None, become_user='root', check=False,
            private_key_file=key, diff=False
        )
        self.key = key
        self.make_inventory(group)
        self.stdout_callback = callback
        self.variable_manager = VariableManager(loader=self.loader, inventory=self.inventory)
        self.play = [] 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:13,代碼來源:playbook.py

示例15: __init__

# 需要導入模塊: from ansible.vars import manager [as 別名]
# 或者: from ansible.vars.manager import VariableManager [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


注:本文中的ansible.vars.manager.VariableManager方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。