def ordered_dump(data, stream=None, Dumper=yaml.SafeDumper, **kwds):
    """Dump a yaml configuration as an OrderedDict."""
    class OrderedDumper(Dumper):
        pass

    def dict_representer(dumper, data):
        return dumper.represent_mapping(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, data.items())

    OrderedDumper.add_representer(OrderedDict, dict_representer)

    return yaml.dump(data, stream, OrderedDumper, **kwds)
Dump a yaml configuration as an OrderedDict.