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


Python RoleInclude.load方法代碼示例

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


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

示例1: resolve_role_to_path

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
def resolve_role_to_path(role_name):
    loader, variable_manager = DataLoader(), VariableManager()
    role_obj = RoleInclude.load(data=role_name, play=None,
                                variable_manager=variable_manager,
                                loader=loader)
    role_path = role_obj._role_path
    return role_path
開發者ID:geerlingguy,項目名稱:ansible-container,代碼行數:9,代碼來源:__init__.py

示例2: get_block_list

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def get_block_list(self, play=None, variable_manager=None, loader=None):

        # only need play passed in when dynamic
        if play is None:
            myplay = self._parent._play
        else:
            myplay = play

        ri = RoleInclude.load(self._role_name, play=myplay, variable_manager=variable_manager, loader=loader)
        ri.vars.update(self.vars)

        # build role
        actual_role = Role.load(ri, myplay, parent_role=self._parent_role, from_files=self._from_files)
        actual_role._metadata.allow_duplicates = self.allow_duplicates

        # save this for later use
        self._role_path = actual_role._role_path

        # compile role with parent roles as dependencies to ensure they inherit
        # variables
        if not self._parent_role:
            dep_chain = []
        else:
            dep_chain = list(self._parent_role._parents)
            dep_chain.append(self._parent_role)

        blocks = actual_role.compile(play=myplay, dep_chain=dep_chain)
        for b in blocks:
            b._parent = self

        # updated available handlers in play
        handlers = actual_role.get_handler_blocks(play=myplay)
        myplay.handlers = myplay.handlers + handlers
        return blocks, handlers
開發者ID:ernstp,項目名稱:ansible,代碼行數:36,代碼來源:role_include.py

示例3: resolve_role_to_path

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
def resolve_role_to_path(role_name):
    loader = DataLoader()
    try:
        variable_manager = VariableManager(loader=loader)
    except TypeError:
        # If Ansible prior to ansible/[email protected]
        variable_manager = VariableManager()
    role_obj = RoleInclude.load(data=role_name, play=None,
                                variable_manager=variable_manager,
                                loader=loader)
    role_path = role_obj._role_path
    return role_path
開發者ID:ansible,項目名稱:ansible-container,代碼行數:14,代碼來源:__init__.py

示例4: test_load_role_with_handlers

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def test_load_role_with_handlers(self):

        fake_loader = DictDataLoader({
            "/etc/ansible/roles/foo_handlers/handlers/main.yml": """
            - name: test handler
              shell: echo 'hello world'
            """,
        })

        i = RoleInclude.load('foo_handlers', loader=fake_loader)
        r = Role.load(i)

        self.assertEqual(len(r._handler_blocks), 1)
        assert isinstance(r._handler_blocks[0], Block)
開發者ID:ferhaty,項目名稱:ansible,代碼行數:16,代碼來源:test_role.py

示例5: test_load_role_with_tasks

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def test_load_role_with_tasks(self):

        fake_loader = DictDataLoader({
            "/etc/ansible/roles/foo_tasks/tasks/main.yml": """
            - shell: echo 'hello world'
            """,
        })

        i = RoleInclude.load('foo_tasks', loader=fake_loader)
        r = Role.load(i)

        self.assertEqual(str(r), 'foo_tasks')
        self.assertEqual(len(r._task_blocks), 1)
        assert isinstance(r._task_blocks[0], Block)
開發者ID:ferhaty,項目名稱:ansible,代碼行數:16,代碼來源:test_role.py

示例6: test_load_role_complex

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def test_load_role_complex(self):

        # FIXME: add tests for the more complex uses of
        #        params and tags/when statements

        fake_loader = DictDataLoader({
            "/etc/ansible/roles/foo_complex/tasks/main.yml": """
            - shell: echo 'hello world'
            """,
        })

        i = RoleInclude.load(dict(role='foo_complex'), loader=fake_loader)
        r = Role.load(i)

        self.assertEqual(r.get_name(), "foo_complex")
開發者ID:ferhaty,項目名稱:ansible,代碼行數:17,代碼來源:test_role.py

示例7: test_load_role_with_vars

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def test_load_role_with_vars(self):

        fake_loader = DictDataLoader({
            "/etc/ansible/roles/foo_vars/defaults/main.yml": """
            foo: bar
            """,
            "/etc/ansible/roles/foo_vars/vars/main.yml": """
            foo: bam
            """,
        })

        i = RoleInclude.load('foo_vars', loader=fake_loader)
        r = Role.load(i)

        self.assertEqual(r._default_vars, dict(foo='bar'))
        self.assertEqual(r._role_vars, dict(foo='bam'))
開發者ID:ferhaty,項目名稱:ansible,代碼行數:18,代碼來源:test_role.py

示例8: load_list_of_roles

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
def load_list_of_roles(ds, loader=None):
    """
    Loads and returns a list of RoleInclude objects from the datastructure
    list of role definitions
    """

    # we import here to prevent a circular dependency with imports
    from ansible.playbook.role.include import RoleInclude

    assert isinstance(ds, list)

    roles = []
    for role_def in ds:
        i = RoleInclude.load(role_def, loader=loader)
        roles.append(i)

    return roles
開發者ID:jinnko,項目名稱:ansible,代碼行數:19,代碼來源:helpers.py

示例9: load_list_of_roles

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
def load_list_of_roles(ds, play, current_role_path=None, variable_manager=None, loader=None):
    '''
    Loads and returns a list of RoleInclude objects from the datastructure
    list of role definitions
    '''

    # we import here to prevent a circular dependency with imports
    from ansible.playbook.role.include import RoleInclude

    assert isinstance(ds, list)

    roles = []
    for role_def in ds:
        i = RoleInclude.load(role_def, play=play, current_role_path=current_role_path, variable_manager=variable_manager, loader=loader)
        roles.append(i)

    return roles
開發者ID:JaredPennella,項目名稱:DevOps_Script,代碼行數:19,代碼來源:helpers.py

示例10: test_load_role_with_vars_dir_vs_file

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def test_load_role_with_vars_dir_vs_file(self):

        fake_loader = DictDataLoader({
            "/etc/ansible/roles/foo_vars/vars/main/foo.yml": """
            foo: bar
            """,
            "/etc/ansible/roles/foo_vars/vars/main.yml": """
            foo: bam
            """,
        })

        mock_play = MagicMock()
        mock_play.ROLE_CACHE = {}

        i = RoleInclude.load('foo_vars', play=mock_play, loader=fake_loader)
        r = Role.load(i, play=mock_play)

        self.assertEqual(r._role_vars, dict(foo='bam'))
開發者ID:awiddersheim,項目名稱:ansible,代碼行數:20,代碼來源:test_role.py

示例11: load_list_of_roles

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
def load_list_of_roles(ds, current_role_path=None, variable_manager=None, loader=None):
    '''
    Loads and returns a list of RoleInclude objects from the datastructure
    list of role definitions
    '''

    # we import here to prevent a circular dependency with imports
    from ansible.playbook.role.include import RoleInclude

    if not isinstance(ds, list):
        raise AnsibleParserError('roles has bad type: "%s". Expectes "list"' % type(ds).__name__, obj=ds)

    roles = []
    for role_def in ds:
        i = RoleInclude.load(role_def, current_role_path=current_role_path, variable_manager=variable_manager, loader=loader)
        roles.append(i)

    return roles
開發者ID:ferhaty,項目名稱:ansible,代碼行數:20,代碼來源:helpers.py

示例12: test_load_role_with_metadata

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def test_load_role_with_metadata(self):

        fake_loader = DictDataLoader({
            '/etc/ansible/roles/foo_metadata/meta/main.yml': """
                allow_duplicates: true
                dependencies:
                  - bar_metadata
                galaxy_info:
                  a: 1
                  b: 2
                  c: 3
            """,
            '/etc/ansible/roles/bar_metadata/meta/main.yml': """
                dependencies:
                  - baz_metadata
            """,
            '/etc/ansible/roles/baz_metadata/meta/main.yml': """
                dependencies:
                  - bam_metadata
            """,
            '/etc/ansible/roles/bam_metadata/meta/main.yml': """
                dependencies: []
            """,
            '/etc/ansible/roles/bad1_metadata/meta/main.yml': """
                1
            """,
            '/etc/ansible/roles/bad2_metadata/meta/main.yml': """
                foo: bar
            """,
            '/etc/ansible/roles/recursive1_metadata/meta/main.yml': """
                dependencies: ['recursive2_metadata']
            """,
            '/etc/ansible/roles/recursive2_metadata/meta/main.yml': """
                dependencies: ['recursive1_metadata']
            """,
        })

        mock_play = MagicMock()
        mock_play.ROLE_CACHE = {}

        i = RoleInclude.load('foo_metadata', play=mock_play, loader=fake_loader)
        r = Role.load(i, play=mock_play)

        role_deps = r.get_direct_dependencies()

        self.assertEqual(len(role_deps), 1)
        self.assertEqual(type(role_deps[0]), Role)
        self.assertEqual(len(role_deps[0].get_parents()), 1)
        self.assertEqual(role_deps[0].get_parents()[0], r)
        self.assertEqual(r._metadata.allow_duplicates, True)
        self.assertEqual(r._metadata.galaxy_info, dict(a=1, b=2, c=3))

        all_deps = r.get_all_dependencies()
        self.assertEqual(len(all_deps), 3)
        self.assertEqual(all_deps[0].get_name(), 'bam_metadata')
        self.assertEqual(all_deps[1].get_name(), 'baz_metadata')
        self.assertEqual(all_deps[2].get_name(), 'bar_metadata')

        i = RoleInclude.load('bad1_metadata', play=mock_play, loader=fake_loader)
        self.assertRaises(AnsibleParserError, Role.load, i, play=mock_play)

        i = RoleInclude.load('bad2_metadata', play=mock_play, loader=fake_loader)
        self.assertRaises(AnsibleParserError, Role.load, i, play=mock_play)

        i = RoleInclude.load('recursive1_metadata', play=mock_play, loader=fake_loader)
        self.assertRaises(AnsibleError, Role.load, i, play=mock_play)
開發者ID:JaredPennella,項目名稱:DevOps_Script,代碼行數:68,代碼來源:test_role.py

示例13: test_load_role_with_metadata

# 需要導入模塊: from ansible.playbook.role.include import RoleInclude [as 別名]
# 或者: from ansible.playbook.role.include.RoleInclude import load [as 別名]
    def test_load_role_with_metadata(self):

        fake_loader = DictDataLoader(
            {
                "/etc/ansible/roles/foo/meta/main.yml": """
                allow_duplicates: true
                dependencies:
                  - bar
                galaxy_info:
                  a: 1
                  b: 2
                  c: 3
            """,
                "/etc/ansible/roles/bar/meta/main.yml": """
                dependencies:
                  - baz
            """,
                "/etc/ansible/roles/baz/meta/main.yml": """
                dependencies:
                  - bam
            """,
                "/etc/ansible/roles/bam/meta/main.yml": """
                dependencies: []
            """,
                "/etc/ansible/roles/bad1/meta/main.yml": """
                1
            """,
                "/etc/ansible/roles/bad2/meta/main.yml": """
                foo: bar
            """,
                "/etc/ansible/roles/recursive1/meta/main.yml": """
                dependencies: ['recursive2']
            """,
                "/etc/ansible/roles/recursive2/meta/main.yml": """
                dependencies: ['recursive1']
            """,
            }
        )

        i = RoleInclude.load("foo", loader=fake_loader)
        r = Role.load(i)

        role_deps = r.get_direct_dependencies()

        self.assertEqual(len(role_deps), 1)
        self.assertEqual(type(role_deps[0]), Role)
        self.assertEqual(len(role_deps[0].get_parents()), 1)
        self.assertEqual(role_deps[0].get_parents()[0], r)
        self.assertEqual(r._metadata.allow_duplicates, True)
        self.assertEqual(r._metadata.galaxy_info, dict(a=1, b=2, c=3))

        all_deps = r.get_all_dependencies()
        self.assertEqual(len(all_deps), 3)
        self.assertEqual(all_deps[0].get_name(), "bar")
        self.assertEqual(all_deps[1].get_name(), "baz")
        self.assertEqual(all_deps[2].get_name(), "bam")

        i = RoleInclude.load("bad1", loader=fake_loader)
        self.assertRaises(AnsibleParserError, Role.load, i)

        i = RoleInclude.load("bad2", loader=fake_loader)
        self.assertRaises(AnsibleParserError, Role.load, i)

        i = RoleInclude.load("recursive1", loader=fake_loader)
        self.assertRaises(AnsibleError, Role.load, i)
開發者ID:jinnko,項目名稱:ansible,代碼行數:67,代碼來源:test_role.py


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