diff --git a/lib/ansible/plugins/lookup/ini.py b/lib/ansible/plugins/lookup/ini.py index 4403b69393b..f2449edafc0 100644 --- a/lib/ansible/plugins/lookup/ini.py +++ b/lib/ansible/plugins/lookup/ini.py @@ -49,10 +49,7 @@ EXAMPLES = """ - debug: msg: "{{ item }}" with_ini: - - value[1-2] - - section: section1 - - file: "lookup.ini" - - re: true + - '.* section=section1 file=test.ini re=True' """ RETURN = """ @@ -130,13 +127,15 @@ class LookupModule(LookupBase): for param in params[1:]: name, value = param.split('=') if name not in paramvals: - raise AnsibleAssertionError('%s not in paramvals' % name) + raise AnsibleAssertionError('%s not in paramvals' % + name) paramvals[name] = value except (ValueError, AssertionError) as e: raise AnsibleError(e) # Retrieve file path - path = self.find_file_in_search_path(variables, 'files', paramvals['file']) + path = self.find_file_in_search_path(variables, 'files', + paramvals['file']) # Create StringIO later used to parse ini config = StringIO() @@ -147,12 +146,14 @@ class LookupModule(LookupBase): # Open file using encoding contents, show_data = self._loader._get_file_contents(path) - contents = to_text(contents, errors='surrogate_or_strict', encoding=paramvals['encoding']) + contents = to_text(contents, errors='surrogate_or_strict', + encoding=paramvals['encoding']) config.write(contents) config.seek(0, os.SEEK_SET) self.cp.readfp(config) - var = self.get_value(key, paramvals['section'], paramvals['default'], paramvals['re']) + var = self.get_value(key, paramvals['section'], + paramvals['default'], paramvals['re']) if var is not None: if isinstance(var, MutableSequence): for v in var: diff --git a/test/units/plugins/lookup/test_ini.py b/test/units/plugins/lookup/test_ini.py index eaa800166be..3902dd29b0e 100644 --- a/test/units/plugins/lookup/test_ini.py +++ b/test/units/plugins/lookup/test_ini.py @@ -31,27 +31,27 @@ class TestINILookup(unittest.TestCase): # Simple case dict( term=u'keyA section=sectionA file=/path/to/file', - expected=[u'keyA', u'section=sectionA', u'file=/path/to/file'], + expected=[u'file=/path/to/file', u'keyA', u'section=sectionA'], ), dict( term=u'keyB section=sectionB with space file=/path/with/embedded spaces and/file', - expected=[u'keyB', u'section=sectionB with space', u'file=/path/with/embedded spaces and/file'], + expected=[u'file=/path/with/embedded spaces and/file', u'keyB', u'section=sectionB with space'], ), dict( term=u'keyC section=sectionC file=/path/with/equals/cn=com.ansible', - expected=[u'keyC', u'section=sectionC', u'file=/path/with/equals/cn=com.ansible'], + expected=[u'file=/path/with/equals/cn=com.ansible', u'keyC', u'section=sectionC'], ), dict( term=u'keyD section=sectionD file=/path/with space and/equals/cn=com.ansible', - expected=[u'keyD', u'section=sectionD', u'file=/path/with space and/equals/cn=com.ansible'], + expected=[u'file=/path/with space and/equals/cn=com.ansible', u'keyD', u'section=sectionD'], ), dict( term=u'keyE section=sectionE file=/path/with/unicode/くらとみ/file', - expected=[u'keyE', u'section=sectionE', u'file=/path/with/unicode/くらとみ/file'], + expected=[u'file=/path/with/unicode/くらとみ/file', u'keyE', u'section=sectionE'], ), dict( term=u'keyF section=sectionF file=/path/with/utf 8 and spaces/くらとみ/file', - expected=[u'keyF', u'section=sectionF', u'file=/path/with/utf 8 and spaces/くらとみ/file'], + expected=[u'file=/path/with/utf 8 and spaces/くらとみ/file', u'keyF', u'section=sectionF'], ), ) @@ -65,4 +65,5 @@ class TestINILookup(unittest.TestCase): for testcase in self.old_style_params_data: # print(testcase) params = _parse_params(testcase['term']) + params.sort() self.assertEqual(params, testcase['expected'])