Order my dicts (#58000)

* use orderdict for yaml dictionaries

* clog

* SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

* allow user to toggle odict off

* removed config, since requored to load config

* remove unused import

* Update changelogs/fragments/yaml_orderd_mappings.yml

Co-authored-by: Matt Clay <matt@mystile.com>

* Update lib/ansible/parsing/yaml/objects.py

Co-authored-by: Matt Clay <matt@mystile.com>

* Update lib/ansible/parsing/yaml/objects.py

Co-authored-by: Matt Clay <matt@mystile.com>

Co-authored-by: Matt Clay <matt@mystile.com>
This commit is contained in:
Brian Coca 2020-05-06 11:05:37 -04:00 committed by GitHub
parent 34458f3569
commit 4e72ce805d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- Use OrderedDict by default when importing mappings from YAML.

View file

@ -19,6 +19,7 @@
from __future__ import (absolute_import, division, print_function) from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
import sys
import yaml import yaml
from ansible.module_utils.six import text_type from ansible.module_utils.six import text_type
@ -53,7 +54,17 @@ class AnsibleBaseYAMLObject(object):
ansible_pos = property(_get_ansible_position, _set_ansible_position) ansible_pos = property(_get_ansible_position, _set_ansible_position)
class AnsibleMapping(AnsibleBaseYAMLObject, dict): # try to always use orderddict with yaml, after py3.6 the dict type already does this
odict = dict
if sys.version_info[:2] < (3, 7):
# if python 2.7 or py3 < 3.7
try:
from collections import OrderedDict as odict
except ImportError:
pass
class AnsibleMapping(AnsibleBaseYAMLObject, odict):
''' sub class for dictionaries ''' ''' sub class for dictionaries '''
pass pass