def test_empty_role_just_name(self):
     ds = [{'name': 'bogus_role'}]
     res = helpers.load_list_of_roles(ds, self.mock_play,
                                      variable_manager=self.mock_variable_manager, loader=self.fake_role_loader)
     self.assertIsInstance(res, list)
     for r in res:
         self.assertIsInstance(r, RoleInclude)
示例#2
0
    def _load_dependencies(self, attr, ds):
        '''
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        '''

        roles = []
        if ds:
            if not isinstance(ds, list):
                raise AnsibleParserError("Expected role dependencies to be a list.", obj=self._ds)

            for role_def in ds:
                if isinstance(role_def, string_types) or 'role' in role_def or 'name' in role_def:
                    roles.append(role_def)
                    continue
                try:
                    # role_def is new style: { src: 'galaxy.role,version,name', other_vars: "here" }
                    def_parsed = RoleRequirement.role_yaml_parse(role_def)
                    if def_parsed.get('name'):
                        role_def['name'] = def_parsed['name']
                    roles.append(role_def)
                except AnsibleError as exc:
                    raise AnsibleParserError(str(exc), obj=role_def)

        current_role_path = None
        if self._owner:
            current_role_path = os.path.dirname(self._owner._role_path)

        try:
            return load_list_of_roles(roles, play=self._owner._play, current_role_path=current_role_path, variable_manager=self._variable_manager,
                                      loader=self._loader)
        except AssertionError:
            raise AnsibleParserError("A malformed list of role dependencies was encountered.", obj=self._ds)
示例#3
0
    def _load_dependencies(self, attr, ds):
        '''
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        '''

        roles = []
        if ds:
            if not isinstance(ds, list):
                raise AnsibleParserError("Expected role dependencies to be a list.", obj=self._ds) 
                
            for role_def in ds: 
                 if isinstance(role_def, string_types) or 'role' in role_def or 'name' in role_def:
                     roles.append(role_def)   
                     continue
                 try:   
                    # role_def is new style: { src: 'galaxy.role,version,name', other_vars: "here" }
                    def_parsed = RoleRequirement.role_yaml_parse(role_def)
                    if def_parsed.get('name'):
                        role_def['name'] = def_parsed['name']  
                    roles.append(role_def)    
                 except AnsibleError as exc:
                     raise AnsibleParserError(str(exc), obj=role_def) 

        current_role_path = None
        if self._owner:
            current_role_path = os.path.dirname(self._owner._role_path)
       
        try:
            return load_list_of_roles(roles, play=self._owner._play, current_role_path=current_role_path, variable_manager=self._variable_manager, loader=self._loader)
        except AssertionError:
            raise AnsibleParserError("A malformed list of role dependencies was encountered.", obj=self._ds)
示例#4
0
 def test_empty_role_just_name(self):
     ds = [{'name': 'bogus_role'}]
     res = helpers.load_list_of_roles(ds, self.mock_play,
                                      variable_manager=self.mock_variable_manager, loader=self.fake_role_loader)
     self.assertIsInstance(res, list)
     for r in res:
         self.assertIsInstance(r, RoleInclude)
示例#5
0
    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,
                collection_search_list=self.collections)
        except AssertionError as e:
            raise AnsibleParserError(
                "A malformed role declaration was encountered.",
                obj=self._ds,
                orig_exc=e)

        roles = []
        for ri in role_includes:
            roles.append(Role.load(ri, play=self))

        self.roles[:0] = roles

        return self.roles
示例#6
0
 def test_block_unknown_action(self):
     ds = [{
         'block': [{'action': 'foo_test_block_unknown_action'}]
     }]
     ds = [{'name': 'bogus_role'}]
     res = helpers.load_list_of_roles(ds, self.mock_play,
                                      variable_manager=self.mock_variable_manager, loader=self.fake_role_loader)
     self.assertIsInstance(res, list)
     for r in res:
         self.assertIsInstance(r, RoleInclude)
 def test_block_unknown_action(self):
     ds = [{
         'block': [{'action': 'foo_test_block_unknown_action'}]
     }]
     ds = [{'name': 'bogus_role'}]
     res = helpers.load_list_of_roles(ds, self.mock_play,
                                      variable_manager=self.mock_variable_manager, loader=self.fake_role_loader)
     self.assertIsInstance(res, list)
     for r in res:
         self.assertIsInstance(r, RoleInclude)
示例#8
0
    def _load_dependencies(self, attr, ds):
        '''
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        '''

        current_role_path = None
        if self._owner:
            current_role_path = os.path.dirname(self._owner._role_path)

        return load_list_of_roles(ds, current_role_path=current_role_path, variable_manager=self._variable_manager, loader=self._loader)
示例#9
0
文件: play.py 项目: dataxu/ansible
    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
示例#10
0
    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
示例#11
0
    def _load_dependencies(self, attr, ds):
        '''
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        '''

        current_role_path = None
        if self._owner:
            current_role_path = os.path.dirname(self._owner._role_path)

        return load_list_of_roles(ds,
                                  current_role_path=current_role_path,
                                  variable_manager=self._variable_manager,
                                  loader=self._loader)
示例#12
0
    def _load_dependencies(self, attr, ds):
        '''
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        '''

        roles = []
        if ds:
            if not isinstance(ds, list):
                raise AnsibleParserError("Expected role dependencies to be a list.", obj=self._ds)

            for role_def in ds:
                if isinstance(role_def, string_types) or 'role' in role_def or 'name' in role_def:
                    roles.append(role_def)
                    continue
                try:
                    # role_def is new style: { src: 'galaxy.role,version,name', other_vars: "here" }
                    def_parsed = RoleRequirement.role_yaml_parse(role_def)
                    if def_parsed.get('name'):
                        role_def['name'] = def_parsed['name']
                    roles.append(role_def)
                except AnsibleError as exc:
                    raise AnsibleParserError(to_native(exc), obj=role_def, orig_exc=exc)

        current_role_path = None
        collection_search_list = None

        if self._owner:
            current_role_path = os.path.dirname(self._owner._role_path)

            # if the calling role has a collections search path defined, consult it
            collection_search_list = self._owner.collections[:] or []

            # if the calling role is a collection role, ensure that its containing collection is searched first
            owner_collection = self._owner._role_collection
            if owner_collection:
                collection_search_list = [c for c in collection_search_list if c != owner_collection]
                collection_search_list.insert(0, owner_collection)
            # ensure fallback role search works
            if 'ansible.legacy' not in collection_search_list:
                collection_search_list.append('ansible.legacy')

        try:
            return load_list_of_roles(roles, play=self._owner._play, current_role_path=current_role_path,
                                      variable_manager=self._variable_manager, loader=self._loader,
                                      collection_search_list=collection_search_list)
        except AssertionError as e:
            raise AnsibleParserError("A malformed list of role dependencies was encountered.", obj=self._ds, orig_exc=e)
示例#13
0
    def _load_dependencies(self, attr, ds):
        '''
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        '''

        if ds is None:
            ds = []

        current_role_path = None
        if self._owner:
            current_role_path = os.path.dirname(self._owner._role_path)

        try:
            return load_list_of_roles(ds, play=self._owner._play, current_role_path=current_role_path, variable_manager=self._variable_manager, loader=self._loader)
        except AssertionError:
            raise AnsibleParserError("A malformed list of role dependencies was encountered.", obj=self._ds)
示例#14
0
    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
示例#15
0
    def _load_dependencies(self, attr, ds):
        '''
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        '''

        if ds is None:
            ds = []

        current_role_path = None
        if self._owner:
            current_role_path = os.path.dirname(self._owner._role_path)

        try:
            return load_list_of_roles(ds,
                                      play=self._owner._play,
                                      current_role_path=current_role_path,
                                      variable_manager=self._variable_manager,
                                      loader=self._loader)
        except AssertionError:
            raise AnsibleParserError(
                "A malformed list of role dependencies was encountered.",
                obj=self._ds)
示例#16
0
 def _load_dependencies(self, attr, ds):
     '''
     This is a helper loading function for the dependencies list,
     which returns a list of RoleInclude objects
     '''
     return load_list_of_roles(ds, loader=self._loader)
示例#17
0
 def _load_roles(self, attr, ds):
     '''
     Loads and returns a list of RoleInclude objects from the datastructure
     list of role definitions
     '''
     return load_list_of_roles(ds, loader=self._loader)