I am would like the ability to set OrderedDicts as the default dictionary class when parsing yaml files, primarily for the purposes of allowing dictionaries in vars to be automatically ordered.
Using Ansible as an API, and building a wrapper around Playbook, I can mostly achieve this, however there are are few issues, that make it complicated.
So I wanted to ask here if there was any interest in allowing OrderedDicts directly in Ansible (e.g. with a config option to enable it) , or failing that whether it was possible to merge in some changes that are blocking me from taking this approach even when using Ansible as an API.
Here are the areas affected:
1) Numerous conditions in various Ansible files that check if a value == dict or != dict, rather than using is_instance(value, dict) therefore subclasses of dict will not work. Is there a particular reason why these checks are so specific?
2) If ordered dicts are used then, it will be necessary to pass in the OrdereredDict class as a global when using utils.safe_eval(), so when a template returns the string form of an OrderedDict it can be evaluated correctly.
3) Finally, if points 1 + 2 are resolved, then some yaml constructors could be added that allow the option of setting the default dict class as OrderedDict for all yaml files.
Interested to get feedback on this, and more than willing to create the relevant pull requests if required.