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


Python Role.load方法代码示例

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


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

示例1: get_block_list

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

示例2: _load_roles

# 需要导入模块: from ansible.playbook.role import Role [as 别名]
# 或者: from ansible.playbook.role.Role import load [as 别名]
    def _load_roles(self, attr, ds):
        '''
        Loads and returns a list of RoleInclude objects from the datastructure
        list of role definitions and creates the Role from those objects
        '''

        role_includes = load_list_of_roles(ds, variable_manager=self._variable_manager, loader=self._loader)

        roles = []
        for ri in role_includes:
            roles.append(Role.load(ri))
        return roles
开发者ID:dataxu,项目名称:ansible,代码行数:14,代码来源:play.py

示例3: test_load_role_with_handlers

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

示例4: test_load_role_with_tasks

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

示例5: test_load_role_complex

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

示例6: test_load_role_with_vars

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

示例7: _load_roles

# 需要导入模块: from ansible.playbook.role import Role [as 别名]
# 或者: from ansible.playbook.role.Role import load [as 别名]
    def _load_roles(self, attr, ds):
        '''
        Loads and returns a list of RoleInclude objects from the datastructure
        list of role definitions and creates the Role from those objects
        '''

        if ds is None:
            ds = []

        try:
            role_includes = load_list_of_roles(ds, play=self, variable_manager=self._variable_manager, loader=self._loader)
        except AssertionError:
            raise AnsibleParserError("A malformed role declaration was encountered.", obj=self._ds)

        roles = []
        for ri in role_includes:
            roles.append(Role.load(ri, play=self))
        return roles
开发者ID:2ndQuadrant,项目名称:ansible,代码行数:20,代码来源:play.py

示例8: test_load_role_with_vars_dir_vs_file

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

示例9: _compile_roles

# 需要导入模块: from ansible.playbook.role import Role [as 别名]
# 或者: from ansible.playbook.role.Role import load [as 别名]
    def _compile_roles(self):
        '''
        Handles the role compilation step, returning a flat list of tasks
        with the lowest level dependencies first. For example, if a role R
        has a dependency D1, which also has a dependency D2, the tasks from
        D2 are merged first, followed by D1, and lastly by the tasks from
        the parent role R last. This is done for all roles in the Play.
        '''

        task_list = []

        if len(self.roles) > 0:
            for ri in self.roles:
                # The internal list of roles are actualy RoleInclude objects,
                # so we load the role from that now
                role = Role.load(ri)

                # FIXME: evauluate conditional of roles here?
                task_list.extend(role.compile())

        return task_list
开发者ID:jinnko,项目名称:ansible,代码行数:23,代码来源:play.py

示例10: test_load_role_with_metadata

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

示例11: test_load_role_with_metadata

# 需要导入模块: from ansible.playbook.role import Role [as 别名]
# 或者: from ansible.playbook.role.Role 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.Role.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。