Fix config_template to consistently order sections

In ec042219e6 we added OrderedDict and
sorted to be able to preserve order for config_template k,v pairs inside
a section.

This patch adds a similar ordering for the sections themselves, which
could still change order and intiiate handler restarts.

OrderedDict isn't needed because we use .items() to return a list that
can then be sorted().
pull/2433/merge
Andy McCrae 2018-03-16 15:24:53 +00:00 committed by Guillaume Abrioux
parent 388562a4af
commit fe4ba9d135
2 changed files with 6 additions and 8 deletions

View File

@ -26,7 +26,6 @@ from ansible import errors
from ansible.runner.return_data import ReturnData
from ansible import utils
from ansible.utils import template
from collections import OrderedDict
CONFIG_TYPES = {
'ini': 'return_config_overrides_ini',
@ -145,14 +144,14 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
def write(self, fp):
if self._defaults:
fp.write("[%s]\n" % 'DEFAULT')
for key, value in OrderedDict(sorted(self._defaults.items())).items():
for key, value in sorted(self._defaults.items()):
self._write_check(fp, key=key, value=value)
else:
fp.write("\n")
for section in self._sections:
for section in sorted(self._sections):
fp.write("[%s]\n" % section)
for key, value in OrderedDict(sorted(self._sections[section].items())).items():
for key, value in sorted(self._sections[section].items()):
self._write_check(fp, key=key, value=value, section=True)
else:
fp.write("\n")

View File

@ -37,7 +37,6 @@ from ansible.plugins.action import ActionBase
from ansible.utils.unicode import to_bytes, to_unicode
from ansible import constants as C
from ansible import errors
from collections import OrderedDict
CONFIG_TYPES = {
'ini': 'return_config_overrides_ini',
@ -173,14 +172,14 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
def write(self, fp):
if self._defaults:
fp.write("[%s]\n" % 'DEFAULT')
for key, value in OrderedDict(sorted(self._defaults.items())).items():
for key, value in sorted(self._defaults.items()):
self._write_check(fp, key=key, value=value)
else:
fp.write("\n")
for section in self._sections:
for section in sorted(self._sections):
fp.write("[%s]\n" % section)
for key, value in OrderedDict(sorted(self._sections[section].items())).items():
for key, value in sorted(self._sections[section].items()):
self._write_check(fp, key=key, value=value, section=True)
else:
fp.write("\n")