plugins/actions/config_template.py
def return_config_overrides_ini(self,
                                    config_overrides,
                                    resultant,
                                    list_extend=True,
                                    ignore_none_type=True,
                                    default_section='DEFAULT'):
        """Returns string value from a modified config file and dict of
        merged config

        :param config_overrides: ``dict``
        :param resultant: ``str`` || ``unicode``
        :returns: ``str``, ``dict``
        """
        # If there is an exception loading the RawConfigParser The config obj
        #  is loaded again without the extra option. This is being done to
        #  support older python.
        try:
            config = ConfigTemplateParser(
                allow_no_value=True,
                dict_type=MultiKeyDict,
                ignore_none_type=ignore_none_type,
                default_section=default_section
            )
            config.optionxform = str
        except Exception:
            config = ConfigTemplateParser(dict_type=MultiKeyDict)

        config_object = StringIO(resultant)
        config.readfp(config_object)

        for section, items in config_overrides.items():
            # If the items value is not a dictionary it is assumed that the
            #  value is a default item for this config type.
            if not isinstance(items, dict):
                if isinstance(items, list):
                    items = ','.join(to_text(i) for i in items)
                self._option_write(
                    config,
                    'DEFAULT',
                    section,
                    items
                )
            else:
                # Attempt to add a section to the config file passing if
                #  an error is raised that is related to the section
                #  already existing.
                try:
                    config.add_section(section)
                except (ConfigParser.DuplicateSectionError, ValueError):
                    pass
                for key, value in items.items():
                    try:
                        self._option_write(config, section, key, value)
                    except ConfigParser.NoSectionError as exp:
                        error_msg = str(exp)
                        error_msg += (
                            ' Try being more explicit with your override'
                            'data. Sections are case sensitive.'
                        )
                        raise errors.AnsibleModuleError(error_msg)

        config_object.close()

        config_dict_new = {}
        config_defaults = config.defaults()
        for s in config.sections():
            config_dict_new[s] = {}
            for k, v in config.items(s):
                if k not in config_defaults or config_defaults[k] != v:
                    config_dict_new[s][k] = v
                else:
                    if default_section in config_dict_new:
                        config_dict_new[default_section][k] = v
                    else:
                        config_dict_new[default_section] = {k: v}

        resultant_stringio = StringIO()
        try:
            config.write(resultant_stringio)
            return resultant_stringio.getvalue(), config_dict_new
        finally:
            resultant_stringio.close()
Returns string value from a modified config file and dict of
        merged config

        :param config_overrides: ``dict``
        :param resultant: ``str`` || ``unicode``
        :returns: ``str``, ``dict``
        
Returns string value from a modified config file and dict of
merged config
Returns string value from a modified config file and dict of merged config
def return_config_overrides_ini(self,
                                    config_overrides,
                                    resultant,
                                    list_extend=True,
                                    ignore_none_type=True,
                                    default_section='DEFAULT'):
        try:
            config = ConfigTemplateParser(
                allow_no_value=True,
                dict_type=MultiKeyDict,
                ignore_none_type=ignore_none_type,
                default_section=default_section
            )
            config.optionxform = str
        except Exception:
            config = ConfigTemplateParser(dict_type=MultiKeyDict)
        config_object = StringIO(resultant)
        config.readfp(config_object)
        for section, items in config_overrides.items():
            if not isinstance(items, dict):
                if isinstance(items, list):
                    items = ','.join(to_text(i) for i in items)
                self._option_write(
                    config,
                    'DEFAULT',
                    section,
                    items
                )
            else:
                try:
                    config.add_section(section)
                except (ConfigParser.DuplicateSectionError, ValueError):
                    pass
                for key, value in items.items():
                    try:
                        self._option_write(config, section, key, value)
                    except ConfigParser.NoSectionError as exp:
                        error_msg = str(exp)
                        error_msg += (
                            ' Try being more explicit with your override'
                            'data. Sections are case sensitive.'
                        )
                        raise errors.AnsibleModuleError(error_msg)
        config_object.close()
        config_dict_new = {}
        config_defaults = config.defaults()
        for s in config.sections():
            config_dict_new[s] = {}
            for k, v in config.items(s):
                if k not in config_defaults or config_defaults[k] != v:
                    config_dict_new[s][k] = v
                else:
                    if default_section in config_dict_new:
                        config_dict_new[default_section][k] = v
                    else:
                        config_dict_new[default_section] = {k: v}
        resultant_stringio = StringIO()
        try:
            config.write(resultant_stringio)
            return resultant_stringio.getvalue(), config_dict_new
        finally:
            resultant_stringio.close()
def return_config_overrides_ini ( self , config_overrides , resultant , list_extend = True , ignore_none_type = True , default_section = 'DEFAULT' ) : try : config = ConfigTemplateParser ( allow_no_value = True , dict_type = MultiKeyDict , ignore_none_type = ignore_none_type , default_section = default_section ) config . optionxform = str except Exception : config = ConfigTemplateParser ( dict_type = MultiKeyDict ) config_object = StringIO ( resultant ) config . readfp ( config_object ) for section , items in config_overrides . items ( ) : if not isinstance ( items , dict ) : if isinstance ( items , list ) : items = ',' . join ( to_text ( i ) for i in items ) self . _option_write ( config , 'DEFAULT' , section , items ) else : try : config . add_section ( section ) except ( ConfigParser . DuplicateSectionError , ValueError ) : pass for key , value in items . items ( ) : try : self . _option_write ( config , section , key , value ) except ConfigParser . NoSectionError as exp : error_msg = str ( exp ) error_msg += ( ' Try being more explicit with your override' 'data. Sections are case sensitive.' ) raise errors . AnsibleModuleError ( error_msg ) config_object . close ( ) config_dict_new = { } config_defaults = config . defaults ( ) for s in config . sections ( ) : config_dict_new [ s ] = { } for k , v in config . items ( s ) : if k not in config_defaults or config_defaults [ k ] != v : config_dict_new [ s ] [ k ] = v else : if default_section in config_dict_new : config_dict_new [ default_section ] [ k ] = v else : config_dict_new [ default_section ] = { k : v } resultant_stringio = StringIO ( ) try : config . write ( resultant_stringio ) return resultant_stringio . getvalue ( ) , config_dict_new finally : resultant_stringio . close ( )
Returns string value from a modified config file and dict of
merged config
Returns string value from a modified config file and dict of merged config
"""Returns string value from a modified config file and dict of
        merged config

        :param config_overrides: ``dict``
        :param resultant: ``str`` || ``unicode``
        :returns: ``str``, ``dict``
        """ # If there is an exception loading the RawConfigParser The config obj #  is loaded again without the extra option. This is being done to #  support older python. # If the items value is not a dictionary it is assumed that the #  value is a default item for this config type. # Attempt to add a section to the config file passing if #  an error is raised that is related to the section #  already existing.
None
self
config_overrides
None
resultant
None
list_extend
ignore_none_type
default_section